您的位置:首页 > 其它

zoj 2001 Adding Reversed Numbers

2011-12-23 12:43 330 查看
#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;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: