国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1002.A + B Problem II

2019-11-06 07:19:12
字體:
來源:轉載
供稿:網友
PRoblem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.Sample Input21 2112233445566778899 998877665544332211Sample OutputCase 1:1 + 2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110

用string保存數字

#include<iostream>#include<string>using namespace std;string add(string &a, string &b){ int c = 0;//進位 if (a.size() < b.size()) return add(b, a); a.assign(a.rbegin(), a.rend()); b.assign(b.rbegin(), b.rend()); int low = 0; while (low < b.size()) { int temp = (a[low] + b[low]-'0'-'0' + c) / 10; a[low] = (a[low] + b[low] - '0' - '0' + c) % 10+'0'; c=temp; low++; } while (low < a.size()) { int temp = (a[low]-'0' + c) / 10; a[low] = (a[low] -'0'+c) % 10+'0'; c = temp; low++; } if (c == 1) a.push_back('1'); a.assign(a.rbegin(), a.rend()); return a;}int main(){ string a, b; int N; cin >> N; for (int t = 1;t <= N;t++) { if (t != 1) cout << endl; cin >> a >> b; printf("Case %d:/n%s + %s = ", t, a.c_str(), b.c_str()); cout << add(a, b) << endl; }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 叶城县| 八宿县| 佛冈县| 南木林县| 忻州市| 临夏市| 理塘县| 青海省| 喀喇| 德庆县| 专栏| 濮阳市| 黔南| 竹溪县| 奎屯市| 灵石县| 祁东县| 德钦县| 隆德县| 寻甸| 吉首市| 庆城县| 千阳县| 酒泉市| 衡东县| 潢川县| 泰和县| 商河县| 罗甸县| 长春市| 无棣县| 黄骅市| 綦江县| 砀山县| 乌兰察布市| 子洲县| 建德市| 颍上县| 东至县| 芦溪县| 灵丘县|