1 /* 2 author:WTZPT 3 Time:2017.7.17 4 Title:Adding Reversed Numbers 5 */ 6 #include<stdio.h> 7 #include<math.h> 8 #include<iostream> 9 using namespace std; 10 int length(int num){ //测试数据长度 11 int i = 0; 12 while(num){ 13 num /= 10; 14 i++; 15 } 16 return i; 17 } 18 19 int trans(int num ,int len){ 20 int temp,sum; 21 sum = 0; 22 while(num){ 23 temp = num % 10; 24 sum += temp*((int)pow(10.0,(len-1)*1.0)); 25 num /= 10; 26 len--; 27 28 } 29 return sum; 30 } 31 int main() 32 { 33 int n,num1,num2,len1,len2,sum1,sum2,sum,len3,num; 34 while(cin>>n){ 35 for(int ii = 0 ; ii < n; ii++) 36 { 37 sum = 0; 38 scanf("%d %d",&num1,&num2); 39 len1 = length(num1); //数据长度 40 len2 = length(num2); 41 //cout<<len1<<" "<<len2<<endl; 测试获取长度函数 42 sum1 = trans(num1,len1);//获得转化后数 43 sum2 = trans(num2,len2); 44 //cout<<sum1<<" "<<sum2<<endl; 测试第一次转化 45 sum = sum1 + sum2; 46 len3 = length(sum); 47 num = trans(sum,len3); 48 cout<<num<<endl; 49 } 50 51 } 52 return 0; 53 }
参考:
http://blog.csdn.net/shiow1991/article/details/7220318
时间: 2024-10-11 07:18:07