zoj 2001 Adding Reversed Numbers

来源:互联网 发布:服务器空间域名备案 编辑:程序博客网 时间:2024/04/28 20:18
#include "iostream"#include "string"#include "sstream"#include "stdio.h"#include "algorithm"using namespace std;int main(){int TestCase;cin >> TestCase;while (TestCase--){string num1, num2, ans;int length;stringstream temp1, temp2, temp;int temp3, temp4, sum;cin >> num1 >> num2;reverse(num1.begin(), num1.end());//反转函数的使用reverse(num2.begin(), num2.end());temp1 << num1;temp1 >> temp3;temp2 << num2;temp2 >> temp4;sum = temp3 + temp4;temp << sum;temp >> ans;reverse(ans.begin(), ans.end());length = ans.size();if (length == 1)cout << ans << endl;else{int count = 0;while (ans[count] == '0') count++;//前导0的统计for (int i = count; i < length; i++)printf("%c", ans[i]);cout << endl;}}}