Strange Addition

来源:互联网 发布:物理机安装centos系统 编辑:程序博客网 时间:2024/05/29 15:05

http://codeforces.com/problemset/problem/305/A


这题就是意思没看懂,一开始以为只要个位数只要一个为0就能相加,没想到到CF里面提交第三组就过不了,才发现是要各个位上面都要有一个为0的时候才能相加。
题意很重要。。。。
AC代码:
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int main(){    int k,i,j,n,t,x,y,z,x1,y1,z1,p;    int d[110],a[110];    while(scanf("%d",&k)!=EOF)    {        for(i = 0; i < k; i++)        {            scanf("%d",&d[i]);        }        sort(d,d+k);        n = 1;        a[0] = d[0];        for(i = 1; i < k; i++)        {            t = d[i];            x = t%10;  //个位            t = t/10;            y = t%10;  //十位            t = t/10;            z = t;     //百位            for(j = 0; j < n; j++)            {                p = a[j];                x1 = p%10;  //个位                p = p/10;                y1 = p%10;  //十位                p = p/10;                z1 = p;     //百位                if((x==0||x1==0)&&(y==0||y1==0)&&(z==0||z1==0))                {                    continue;                }                else                {                    break;                }            }            if(j == n)            {                a[n++] = d[i];            }        }        printf("%d\n%d",n,a[0]);        for(j = 1; j < n; j++)        {            printf(" %d",a[j]);        }        printf("\n");    }    return 0;}


原创粉丝点击