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
The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers separated by space. These are the reversed numbers you are to add.
Output
For each case, print exactly one line containing only one integer - the reversed sum of two reversed numbers. Omit any leading zeros in the output.
Sample Input
3
24 1
4358 754
305 794
Sample Output
34
1998
1
#include <iostream>
#include <math.h>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
int n;
cin>>n;
int c;
for(c=1;c<=n;c++)
{
char num1[100],num2[100];
cin>>num1>>num2;
int len1,len2,sum[100]={0};
len1=strlen(num1);
len2=strlen(num2);
int n1[100]={0},n2[100]={0};
int i;
for(i=0;i<len1;i++)
n1[i]=num1[i]-'0';
for(i=0;i<len2;i++)
n2[i]=num2[i]-'0';
int len;
len=len1>len2?len1:len2;
for(i=0;i<len;i++)
{
sum[i]=sum[i]+n1[i]+n2[i];
if(sum[i]>9)
{
sum[i]=sum[i]-10;
sum[i+1]=sum[i+1]+1;
if(i+1==len)
len=len+1;
}
}
int s=0;
for(i=0;i<len;i++)
{
s=s+sum[i]*pow(10.0,len-i-1);
}
cout<<s<<endl;
}
return 0;
}
/*
3
24 1
4358 754
305 794
*/
刚开始提交时发现编译错误
s=s+sum[i]*pow(10,len-i-1);
后来改成这样就对了
s=s+sum[i]*pow(10.0,len-i-1);
因为,pow这个函数的参数只能是下面几种情况
long double pow(long double,int)
float pow(float,int)'
double pow(double,int)'
即第一个参数必须是float、double、long double中的一个,而你pow(10,len-i-1);第一个参数是10是个int型,找不到匹配的函数。。。如果改成 pow(10.0,len-i-1);才对