您的位置:首页 > 其它

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: