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

本文探讨了一道关于选择特定整数集合的问题,要求集合内的任意两个整数相加时,每个位上至少有一个数字为0。文章给出了问题的背景、具体要求及解决方案,并附带了实现这一逻辑的C++代码。
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 (ab), 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值