1023. Have Fun with Numbers (20)
来源:互联网 发布:流量推广软件 编辑:程序博客网 时间:2024/06/17 08:41
一开始 心存侥幸 用long long 最后三个测试数据通不过 终还是老老实实的用模拟大数运算
思路:用两个数组分别存放 double前后的各位数字出现个数 后比较
<pre name="code" class="html">#include<iostream>#include<vector>#include<cmath>#include<string>#include<cstring>#include<algorithm>#include<iomanip>#include<map>using namespace std;#define Max 100000int main(){ string num1, T1, T2; int a[10], b[10], C; int num2[30], i, j, flag; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); cin>>num1; for(int i=0; i<num1.size(); i++){ a[num1[i]-'0']++; } flag=C=0;//结果标记,进位 for(i=num1.size()-1,j=0; i>=0; i--,j++) { int tmp=(num1[i]-'0')*2; num2[j]=tmp%10+C; C=tmp/10; if(++b[num2[j]]>a[num2[j]]) flag=1; } if(C){//最高位有进位 num2[j]=C; for(i=j; i>=0; i--) T1+=num2[i]+'0'; if(++b[num2[j]]>a[num2[j]]) flag=1; } else for(i=j-1; i>=0; i--) T1+=num2[i]+'0'; if(flag) cout<<"No"<<endl; else cout<<"Yes"<<endl; cout<<T1<<endl; return 0;}
0 0
- 1023. Have Fun with Numbers (20)
- 【PAT】1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- PAT: 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- PAT 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- PAT 1023. Have Fun with Numbers (20)
- PAT 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- 1023. Have Fun with Numbers (20)
- C语言中常用的库函数
- IE的工具栏
- 死循环之间穿梭(51操作系统之抢占式任务切换)
- UE4 Metal Rendering API
- hdoj-2015 偶数求和【水】
- 1023. Have Fun with Numbers (20)
- zzuli OJ 1026: 字符类型判断
- iOS 企业应用的发布要点
- 微信企业号开发:微信考勤摇一摇考勤
- 51操作系统之延时实现源代码
- getview所犯低级错误
- zzuli OJ 1027: 判断水仙花数
- python shape tile **(幂运算)
- OScache为web配置缓存