您的位置:首页 > 其它

codeforces Round #184 Div.2 - A. Strange Addition

2013-05-20 20:54 323 查看
A. Strange Addition

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Unfortunately, Vasya can only sum pairs of integers (a, b),
such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50,
but he cannot sum 1 and 4.

Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.

Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?

Input

The first input line contains integer k (1 ≤ k ≤ 100) —
the number of integers.

The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).

Output

In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct
non-negative integers — the required integers.

If there are multiple solutions, print any of them. You can print the numbers in any order.

Sample test(s)

input
4
100 10 1 0


output
4
0 1 10 100


input
3
2 70 3


output
2
2 70

第一次拿到这题,我有种想哭的感觉,坑爹的题啊!!!
下面说下题目意思:要求在给出的所有的数中选出一些组成集合,满足两两相加每位都至少有一个0。就是给你n个数,找出满足题意的数的个数,怎样才满足题意,(X0与X)两个数或者(X0,X,XX)其中任意一个或者这个数是100或0,下面:100和0是必定满足题意的,还有如果这个题目的范围是大于等0小于等于100,所以无论怎样给出几个数,最后满足题意的数最多不超过4个,因为除了0和100以外最多只能取(X0与X)这两个数,还有特殊的n==1时,这时就是输出这个数,因为题目说了任意取两个数,所以只能取这个数了,下面是代码:
#include<iostream>

const int MAX=200;

int s[MAX];

int t[MAX];

int k[MAX];

using namespace std;

int main()

{
int n,m,i,j,a,b,c,sum,q,p;
cin>>n;
a=0;
b=0;
sum=0;
q=0;
for(i=0;i<n;i++)
{
cin>>s[i];
if(s[i]==0||s[i]==100)
{
t[a]=s[i];
a++;
continue;
}
if((s[i]>9&&s[i]<100)&&s[i]%10==0)
{
q=s[i];
continue;
}
if((s[i]>0&&s[i]<10)&&b==0)
{
t[a]=s[i];
a++;
b=1;
continue;
}
}
c=0;
for(j=0;j<n;j++)
{
if(s[j]>9&&s[j]<100)
{
if(q!=0&&c==0)
{
t[a]=q;
a++;
c=1;
}
if(b==0&&c==0)
{
if(q==0)
{
t[a]=s[j];
a++;
c=1;
}
}
}
}
cout<<a<<endl;
for(i=0;i<a;i++)
{
if(i==a-1)
cout<<t[i]<<endl;
else
cout<<t[i]<<" ";
}
return 0;

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