POJ 2562每日一水
来源:互联网 发布:eclipse查看php版本 编辑:程序博客网 时间:2024/06/07 10:29
给两个不超过十位的正整数,问它们相加的过程中,一共有几次进位。模拟加法运算……
#include <iostream>#include <map>#include <string>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;int main(){ int i,j,l1,l2,sum; string a,b; while(cin>>a>>b) { if(a=="0"&&b=="0") break; int c[15]={0}; sum=0; if(a.length()<b.length()) swap(a,b); //前个数长度比较大,若小的交换 l1=a.length(); l2=b.length(); for(i=l1-1,j=l1; i>=0; i--,j--) { if(i-l1+l2>=0) c[j]+=(a[i]-48)+(b[i-l1+l2]-48); else c[j]+=(a[i]-48); if(c[j]>9) { sum++; c[j-1]+=1; c[j]-=10; } } if(sum==0) cout<<"No carry operation."<<endl; else if(sum==1) cout<<"1 carry operation."<<endl; else cout<<sum<<" carry operations."<<endl; } return 0;}
- POJ 2562每日一水
- POJ 2328每日一水
- 【每日一水】toj1038
- 每日一水 POJ8道水题
- 【每日一水】[toj1093]Argus
- HDU 1172 每日一水
- poj每日一题之1001(求高精度幂)
- poj每日一题之1002(487-3279)
- 每日一dp(3)——POJ 1141 Brackets Sequence
- 每日一搜——poj搜索题目分类
- 每日一题(5)poj,1258, AgriNet
- 【每日一题(11)】Wine Trading in Gergovia POJ
- 每日打卡 2017.03.12 POJ题目分类 初级-一、基本算法
- 每日一笑1
- 每日一笑(2)
- 每日一笑(3)
- 每日一笑(4)
- 每日一句(十三)
- win7 32 jadclipse 不生效解决办法
- Java序列化与Java串行化
- C++各种函数为什么能或者不能是虚函数
- linux之shell
- Android SQLite数据库
- POJ 2562每日一水
- J2EE项目整体异常处理机制
- 备忘录
- MFC 删除非空文件夹
- 设计模式9:迭代器模式
- MFC 多语言切换 和 程序重启
- configure: error: C++ compiler cannot create executables
- Linux ——创建快捷方式
- My open source : https://github.com/ndkk/GreatFoundationLibrary