杭电1002 A + B Problem II
来源:互联网 发布:好乐宝软件下载 编辑:程序博客网 时间:2024/05/19 23:16
#include<iostream>#include <string>using namespace std;/*int main(){ int sum[1000]; int temp=0; string aL; string bL; int n1,n2,n,tem; int k,t=1,u,v; cin >> k; for (int w = 0; w < k; w++) { cin >> aL >> bL; n1 = aL.length(); n2 = bL.length(); int sum[1000]; int q; tem = abs(n1 - n2); if (n1>=n2) { q = 0; int i = n2 - 1; //cout << "已运行flag1" << endl; while (i>=0) { if (aL[i + tem]-48 + bL[i]-48 +temp>= 10) { //cout << aL[i + tem]-48<< " " << bL[i]-48 << " "<<temp<<" "<<i<<endl; sum[q++] = (aL[i + tem]-48 + bL[i]-48+temp) % 10; //cout << sum[q-1] << endl; temp = (aL[i + tem]-48 + bL[i]-48 + temp) / 10; } else { //cout << aL[i + tem]-48 << " " << bL[i]-48 << " " << temp <<" "<< i<<endl; sum[q++] = aL[i + tem]-48 + bL[i]-48+temp; //cout << sum[q - 1] << endl; temp = (aL[i + tem]-48 + bL[i]-48 + temp) / 10; } u = tem; i--; } if ((u==0)&&(temp !=0)) { sum[q++] = temp; //cout << sum[q - 1] << endl; temp = 0; } while (u >0) { //cout << aL[u - 1]-48 << " " << temp <<" "<<u<< endl; sum[q++] = (aL[u-1]-48 + temp) % 10; //cout << sum[q - 1] << endl; temp = (aL[u - 1]-48 + temp) / 10;; u--; } if (temp !=0) { sum[q++] = temp; //cout << sum[q - 1] << endl; temp = 0; } } if (n1<n2) { q = 0; int i= n1 - 1; //cout << "已运行flag2" << endl; while(i>=0) { if (bL[i + tem]-48 + aL[i]-48+temp >= 10) { //cout << bL[i + tem]-48 << " " << aL[i]-48 <<" "<<temp<<" "<< i<<endl; sum[q++] = (bL[i + tem]-48 + aL[i]-48+temp) % 10; //cout << sum[q-1] << endl; temp = 1; } else { //cout << bL[i + tem]-48 << " " << aL[i]-48 << " " << temp <<" "<<i<< endl; sum[q++] = bL[i + tem]-48 + aL[i]-48+temp; //cout << sum[q-1] << endl; temp = (bL[i + tem]-48 + aL[i]-48 + temp) / 10; } v = tem; i--; } if ((v == 0) && (temp != 0)) { sum[q++] = temp; temp = 0; } while (v>0) { //cout << bL[v - 1]-48 << " " << temp <<" "<< v<<endl; sum[q++] = (bL[v-1]-48 + temp) % 10; //cout << sum[q-1] << endl; temp = (bL[v-1]-48 + temp) / 10; v--; } if (temp !=0) { sum[q++] = temp; temp = 0; } } cout << "Case" << " " << w + 1 << ":" << endl; cout << aL<<" + "<<bL<<" = "; //cout << " " << "+" << " "; //cout << bL; //cout << " " << "=" << " "; for (int i = q-1; i>=0; i--) { //cout << t++ << endl; cout << sum[i]; } cout << endl; if (w < k- 1) cout << endl; //cout <<"\n"<< endl; } return 0;}*/
阅读全文
0 0
- 杭电 1002[A + B Problem II]
- 杭电1002 A + B Problem II
- 杭电 1002:A + B Problem II
- 杭电 1002 A + B Problem II
- 杭电1002 A+B problem II
- 杭电1002 A + B Problem II
- 杭电1002 A + B Problem II
- 杭电1002---A + B Problem II
- 杭电1002 A+B Problem(II)
- 杭电1002 A + B Problem II
- 杭电 1002 A + B Problem II
- 【杭电】[1002]A + B Problem II
- 杭电1002:A + B Problem II
- 杭电-1002 A + B Problem II
- 【杭电1002】A + B Problem II
- 【杭电1002】A + B Problem II
- 【杭电】 1002 A + B Problem II
- 杭电1002 A + B Problem II
- 算法笔记:使用栈实现汉诺塔(Hanoi)经典算法
- 垃圾收集与分配策略——(三)HotSpot的算法实现
- Java注解
- QWT的配置和使用(1)
- java递归浅析合并排序
- 杭电1002 A + B Problem II
- 机器学习之旅:数据预处理的对象-数据
- C++常成员函数和常对象、对象指针和对象引用
- C++11基础-----std::function & std::bind
- 内存中的堆和栈
- java语言基础(98)——定时器和定时任务
- hbase学习教程(三):HBase优化技巧、HBase基本命令、使用Java API对HBase服务器进行操作
- 杭电1003 Max Sum
- NetPerfMeter : A Network Performance Metering Tool Introduction