您的位置:首页 > 其它

CodeForces 614 B. Gena's Code(水~)

2016-02-26 18:57 288 查看
Description

给出n个数,定义美丽数为一个只由01组成且至多含有一个1的数,保证n个数中至少有n-1个美丽数,问这n个数的乘积

Input

第一行为一整数n,之后n行每行一个数字串表示一个数(1<=n<=100000,每个数字长度不会超过100000)

Output

输出这n个数字的乘积

Sample Input

3

5 10 1

Sample Output

50

Solution

美丽数只有两种:0或者10^t,所以记录非美丽数和美丽数中0的个数以及美丽数中是否含0即可

Code

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define maxn 111111
int n,pre,cnt,mark;
char a[maxn],ans[maxn];
int main()
{
while(~scanf("%d",&n))
{
cnt=0,mark=0,ans[0]='\0';
while(n--)
{
scanf("%s",a);
if(a[0]=='0')mark=1;
else if(a[0]=='1')
{
int len=strlen(a),flag=1,temp=0;
for(int i=1;i<len;i++)
if(a[i]!='0')flag=0;
else temp++;
if(!flag)strcat(ans,a);
else cnt+=temp;
}
else if(a[0]!='0')strcat(ans,a);
}
if(mark)printf("0\n");
else
{
if(ans[0])printf("%s",ans);
else printf("1");
for(int i=0;i<cnt;i++)printf("0");
printf("\n");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: