解题报告:codeforces #339(Div.2)B.Gena's Code
2016-01-15 18:25
330 查看
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。
代码:
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"); } }
相关文章推荐
- 极光推送的别名alias和标签tag分别是什么意思
- 第七讲 有依赖的背包问题 vijos P1313金明的预算方案
- 项目修炼之路(1)服务化
- auto_ptr and scoped_ptr
- COGS314. [NOI2004] 郁闷的出纳员
- HDU 2102 A计划
- hdu 3966 Aragorn's Story(树链剖分+树状数组)
- go基本语法学习笔记之并发编程
- chromium for android v34 2dcanvas硬件渲染实现分析
- 我们聊聊快排吧...
- Node.js_Path模块
- 第六讲 分组的背包问题 HDU 1712ACboy needs your help
- php7.0 + mysql5.7.10 + nginx7.0 web开发环境搭建(CentOS7)
- Valgrind使用简
- PHP超大文件下载,断点续传下载
- C++历史段错误
- MFC 的几个重绘
- hadoop安全机制与kerberos
- Spring-webmvc源码解析之ResourceHttpRequestHandler
- 自行编写数字转换成字符串Myatoi()函数