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
给出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; }
相关文章推荐
- 寻路算法合集
- 泛泰A900 刷4.4专用中文TWRP2.7.1.1版 支持自己主动识别手机版本号(全球首创)
- centos下安装fio
- 用yum查询想安装的软件
- 用yum查询想安装的软件
- solve det(I + uv^t)
- 【MFC-11】VS2010/MFC基于对话框程序之修改Enter/ESC按键默认响应
- JDK环境配置
- 兔子增长序列(内测第1届第3题)
- qemu,kvm,qemu-kvm,xen,libvir 区别
- Leetcode 175 Combine Two Table
- linux笔记
- ant用法;
- IPC机制(二)
- C#Winform程序如何使用ClickOnce发布并自动升级(图解)
- Cocoa Touch事件处理流程--响应者链
- 计算字节长度
- Where is the xm Command in XenServer
- [BZOJ2242][SDOI2011]计算器(快速幂+扩欧+BSGS)
- iOS 自定制搜索栏,保存历史搜索