题目描述
Xiao Ming always tends to ignore the carry when he does decimal addition with paper and pencil.For example,15+17,Xiao Ming will answer 22,because he ignores the carry from the single digits.5+7=12,and the digit 1 is the carry.
输入
The input will consist of a series of pairs of integers a and b(both less than 1000000000),separated by a space, one pair of integers per line.
输出
For each pair of input integers a and b you should output the correct answer of the sum of a and b,a space character and Xiao Ming's answer of the sum of a and b in one line,and with one line of output for each line in input.If Xiao Ming's answer begins with zero,don't output unnecessary zero.
样例输入
15 16
1 999
31 71
样例输出
31 21
1000 990
102 2
我的雷人答案:
#include<iostream>
using namespace std;
int main(){
int a,b;
int A,B,C;
while(cin>>a>>b){
A = a+b;
B =
((a/10 +b/10)%10)*10 +
((a/100 +b/100)%10)*100 +
((a/1000 +b/1000)%10)*1000 +
((a/10000 +b/10000)%10)*10000 +
((a/100000 +b/100000)%10)*100000 +
((a/1000000 +b/1000000)%10)*1000000 +
((a/10000000 +b/10000000)%10)*10000000 +
((a/100000000 +b/100000000)%10)*100000000 +
((a/1000000000 +b/1000000000)%10)*1000000000;//题目要求less than 1000000000
C = B + A%10;
cout<<A<<" "<<C<<endl;
}
return 0;
}
版权声明:本文为heathufei原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。