poj 1503(水题)
来源:互联网 发布:javascript 获取时间 编辑:程序博客网 时间:2024/06/05 02:18
大数问题
代码如下
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;int main(){string s;int a[200];memset(a,0,sizeof(a));while(getline(cin,s)){int len=s.size();if(len==1&&s[0]=='0') break;else{int p=0;int cnt=0;for(int i=len-1;i>=0;i--){cnt=cnt+(s[i]-'0');a[p++]+=cnt%10;cnt=cnt/10;}}}int c=0;for(int i=0;i<=150;i++){c=c+a[i];a[i]=(c%10);c=c/10; } int l=-1;for(int i=150;i>=0;i--){if(a[i]==0&&a[i-1]!=0) {l=(i-1);break;}}for(int i=l;i>=0;i--){printf("%d",a[i]);}printf("\n");return 0; }
一个别人写的小技巧
- //去掉前导0
- while(sum[i]==0) i--;
阅读全文
0 0
- poj 1503(水题)
- poj 1503
- POJ-1503
- POJ 1503
- poj 1503
- poj - 1503
- poj 1503
- poj 1503
- POJ 1503
- poj 1503
- poj水题
- POJ 水题
- POJ 水题
- poj水题
- poj 水题
- poj 水题
- POJ水题
- poj水题
- LinkList链表
- 总结:java设计模式之----抽象工厂
- const用法总结
- Java:毫秒数与日期互转
- Log4j
- poj 1503(水题)
- 渲染管线——透视投影变换
- 想拥有一台属于你自己的无人机嘛?
- 新一代数据查询语言GraphQL来啦
- Gradle仓库配置
- 本地的VideoFrame渲染一(VideoTrack)
- eclipseXML(dtd)约束导入
- TCP 的流量控制
- 九大常见的基本排序