Codeforces Round #339 (Div. 2) (B 模拟)

来源:互联网 发布:itunes网络连接超时 编辑:程序博客网 时间:2024/05/30 05:30

这道水题明明不难,然而看错题了,据说这道题用高精度和java大数都是过不去的,一定要注意,数据是十万位,不是小于十万,因为只有一个不美丽数也就是说基本都是0,1,只要把0计数,1超过一次单拿出来,非0非1单拿出来,几乎就没问题了有0的状况,和全都是美丽数的情况要单独考虑一下,哎,还是太菜啊

#include <iostream>#include <string.h>using namespace std;char s[100005],p[100005];int main(){    int T;    while(cin>>T)    {        bool flag=0;        long long sum0=0,ans=0;        while(T--)        {            long long len=0,sum1=0;            bool flag2=0;            memset(s,0,sizeof(s));            cin>>s;            len=strlen(s);            for(int i=0; i<len; i++)            {                if(s[i]=='0'&&len==1)                {                    flag=1;                    break;                }                else if(s[i]=='1')                    sum1++;                else if(s[i]!='0'&&s[i]!='1')                {                    flag2=1;                    break;                }            }            if(flag==1)                continue;            else if(sum1>1||flag2==1)            {                    strcpy(p,s);            }            else            {                for(int i=0; i<len; i++)                {                    if(s[i]=='0')                        sum0++;                }            }        }        if(flag==1)        {            cout<<0<<endl;        }        else        {            if(p[0]!=NULL)            {                cout<<p;            }            else            {                cout<<1;            }            for(int i=1; i<=sum0; i++)                cout<<0;            cout<<endl;        }    }    return 0;}
0 0
原创粉丝点击