标签:des style blog http color strong
Description
Reversed number is a number written in arabic numerals but the order of digits is reversed. The first digit becomes last and vice versa. For example, if the main hero had 1245 strawberries in the tragedy, he has 5421 of them now. Note that all the leading zeros are omitted. That means if the number ends with a zero, the zero is lost by reversing (e.g. 1200 gives 21). Also note that the reversed number never has any trailing zeros.
ACM needs to calculate with reversed numbers. Your task is to add two reversed numbers and output their reversed sum. Of course, the result is not unique because any particular number is a reversed form of several numbers (e.g. 21 could be 12, 120 or 1200 before reversing). Thus we must assume that no zeros were lost by reversing (e.g. assume that the original number was 12).
Input
Output
Sample Input
Sample Output
#include<iostream> using namespace std; int main() { int f(int); int i,n,a,b,t; cin>>n; while(n--) { cin>>a>>b; t=f(f(a)+f(b)); cout<<t<<endl; } } int f(int m) { int r=0; while(m) { r=r*10+m%10; m=m/10; } return r; }
B - Adding Reversed Numbers,布布扣,bubuko.com
标签:des style blog http color strong
原文地址:http://blog.csdn.net/rememberautumn/article/details/37813601