解题报告:codeforces #339(Div.2)B.Gena's Code
来源:互联网 发布:nginx配置https证书 编辑:程序博客网 时间:2024/05/16 07:31
B. Gena's Code
time limit pertest
0.5 seconds
memory limit pertest
256 megabytes
input
standard input
output
standard output
It's the year4527 and the tanks game that we all know and love still exists. There alsoexists Great Gena's code, written in 2016. The problem this code solves is:given the number of tanks that go into the battle from each country, find theirproduct. If it is turns to be too large, then the servers might have not enoughtime to assign tanks into teams and the whole game will collapse!
There areexactly n distinct countries in the world and the i-th countryadded ai tanks tothe game. As the developers of the game are perfectionists, the number of tanksfrom each country is beautiful. A beautiful number, accordingto the developers, is such number that its decimal representation consists onlyof digits '1' and '0', moreover itcontains at most one digit '1'. However, due to complaints from players,some number of tanks of one country was removed from the game,hence the number of tanks of this country may not remain beautiful.
Your task is towrite the program that solves exactly the same problem in order to verifyGena's code correctness. Just in case.
Input
The first lineof the input contains the number of countries n (1 ≤ n ≤ 100 000). The secondline contains n non-negative integers aiwithout leadingzeroes — the number of tanks of the i-th country.
It is guaranteedthat the second line contains at least n - 1 beautifulnumbers and the total length of all these number's representations doesn'texceed 100 000.
Output
Print a singlenumber without leading zeroes — the product of the number of tanks presentedby each country.
Sample test(s)
input
3
5 10 1
output
50
input
4
1 1 10 11
output
110
input
5
0 3 1 100 1
output
0
Note
In sample 1numbers 10 and 1 are beautiful, number 5 is not not.
In sample 2number 11 is not beautiful (contains two '1's), all othersare beautiful.
In sample 3number 3 is not beautiful, all others are beautiful.
题目大意及思路:给你一些数,求乘积,beautifulnumbers的设置降低了难度:最多只会有一个不美的数将其记录下来,其余的都是10的指数的形式,则只用记录长度就好最后输出几个零就好。需要注意的是可能全为合法数,这是需要先输出一个1。
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;char A[100000+5],B[100000+5];int main(){ int n; while(scanf("%d",&n)==1) { int ans=0,m=1,k=0; memset(B,'\0',sizeof(B)); while(n--) { scanf("%s",A); if(A[0]=='0') ans=-1; if(ans==-1) continue; int len=strlen(A); if(k) { ans+=len-1; } else { for(int i=0,num=0;A[i]!='\0'&&!k;i++) { if(A[i]=='1') num++; if(A[i]!='1'&&A[i]!='0') k=1; if(num>1) k=1; } if(k) strcpy(B,A); else ans+=len-1; } } if(ans!=-1) { if(k) printf("%s",B); else printf("1"); for(int i=0;i<ans;i++) printf("0"); } else printf("0"); printf("\n"); }}
- 解题报告:codeforces #339(Div.2)B.Gena's Code
- Codeforces Round #339 (Div. 2) B.Gena's Code
- Codeforces Round #339 (Div. 2) B. Gena's Code
- Codeforces Round #339 (Div. 2) B. Gena's Code
- Codeforces Round #339 (Div. 2) B. Gena's Code
- Codeforces Round #339 (Div. 2)-B. Gena's Code(字符串模拟)
- 【Codeforces Round 339 (Div 2)B】【水题】Gena's Code 若干10数+1特殊数的乘积
- Codeforces - 339B(div2) - Gena's Code(模拟)
- Codeforces 614B Gena's Code
- CodeForces - 614B Gena's Code
- CodeForces 614B Gena's Code
- codeforces 614 B Gena's Code
- CodeForces 614B Gena's Code
- Codeforces Problem 614B Gena's Code
- CodeForces 614 B Gena's Code
- CodeForces 614 B.Gena's Code
- CodeForces 614 B. Gena's Code(水~)
- 614B Gena's Code
- android 拨打特殊字符电话号码
- ListView优化机制及滑动时数据错乱
- Java设计模式之单例模式(Singleton)
- 基数和偶数分离
- 极光推送的别名alias和标签tag分别是什么意思
- 解题报告:codeforces #339(Div.2)B.Gena's Code
- javascript同步异步
- unresolved external symbol __imp____glutInitWithExit
- 配置文件报错:不允许有匹配 "[xX][mM][lL]" 的处理指令目标
- 通过HTTP方式获取URL返回结果数据(Java)
- Gradle学习
- DFS之全排列
- iOS 调用打电话事件
- 在Tomcat配置JNDI数据源的三种方式