Codeforces Round #184 (Div. 2) A题
2013-05-21 09:04
337 查看
今天我终于看懂了这题什么意思了,就是给出一些数,1:把0和100都放进一个集合 2:有整除10的数也放进一个集合中 3:有1——9中的数也放进一个进去
最后输出在这个集合中一共有多少个数,并且可以不按顺序输出来!
#include <iostream>
#include <cstring>
using namespace std;
const int maxn=100+5;
int ans[maxn];
int a[maxn];
bool hash[maxn];
int main()
{
int n;
cin>>n;
int cnt=0,x;
bool flag2=0,flag3=0;
memset(hash,0,sizeof(hash));
for(int i=0;i<n;i++){
cin>>a[i];
x=a[i];
if(x==0) ans[cnt++]=x,hash[x]=1;
else if(x%100==0) ans[cnt++]=x,hash[x]=1;
else if(x%10==0&&!flag2) ans[cnt++]=x,flag2=1,hash[x]=1;
else if(x/10==0&&!flag3) ans[cnt++]=x,flag3=1,hash[x]=1;
}
if(!flag2&&!flag3){
for(int i=0;i<n;i++)
if(!hash[a[i]]){
ans[cnt++]=a[i];
break;
}
}
cout<<cnt<<endl;
for(int i=0;i<cnt;i++)
cout<<ans[i]<<" ";
cout<<endl;
return 0;
}
最后输出在这个集合中一共有多少个数,并且可以不按顺序输出来!
#include <iostream>
#include <cstring>
using namespace std;
const int maxn=100+5;
int ans[maxn];
int a[maxn];
bool hash[maxn];
int main()
{
int n;
cin>>n;
int cnt=0,x;
bool flag2=0,flag3=0;
memset(hash,0,sizeof(hash));
for(int i=0;i<n;i++){
cin>>a[i];
x=a[i];
if(x==0) ans[cnt++]=x,hash[x]=1;
else if(x%100==0) ans[cnt++]=x,hash[x]=1;
else if(x%10==0&&!flag2) ans[cnt++]=x,flag2=1,hash[x]=1;
else if(x/10==0&&!flag3) ans[cnt++]=x,flag3=1,hash[x]=1;
}
if(!flag2&&!flag3){
for(int i=0;i<n;i++)
if(!hash[a[i]]){
ans[cnt++]=a[i];
break;
}
}
cout<<cnt<<endl;
for(int i=0;i<cnt;i++)
cout<<ans[i]<<" ";
cout<<endl;
return 0;
}
相关文章推荐
- Codeforces Round #184 (Div. 2) Continued Fractions 分数计算 long long相乘会越界
- Codeforces Round #184 (Div. 2) E. Playing with String(博弈)
- Codeforces Round #184 (Div. 2)
- Codeforces Round #184 (Div. 2)-B. Continued Fractions
- Codeforces Round #184 (Div. 2) D、E
- Codeforces Round #184 (Div. 2)
- Codeforces Round #184 (Div. 2) B. Continued Fractions
- 输出判断Codeforces Round #184 (Div. 2)
- Codeforces Round #184 (Div. 2)——A,B,C
- Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列
- Codeforces Round #415(Div. 2)-810A.。。。 810B.。。。 810C.。。。不会
- Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法
- Codeforces Round #301 (Div. 2) A,B,C,D,E题解
- 【Codeforces Round 365 (Div 2)D】【离线询问 树状数组 前驱思想】Mishka and Interesting sum 区间内出现次数偶数的数的异或和
- 【CodeForce】Codeforces Round #140 (Div. 2) A B C
- Codeforces Round #469 (Div. 2) C. Zebras
- Codeforces Round #228 (Div. 1) A. Fox and Box Accumulation 贪心
- Codeforces Round #279 (Div. 2) 解题报告(A B C D)
- Codeforces Round #228 (Div. 1) A. Fox and Box Accumulation (贪心)
- Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem(二分染色?/2-sat,好题)