Adding Reversed Numbers(summer2017)

 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

Adding Reversed Numbers(summer2017)的相关文章

UVA713 UVALive5539 POJ1504 ZOJ2001 Adding Reversed Numbers

Regionals 1998 >> Europe - Central 问题链接:UVA713 UVALive5539 POJ1504 ZOJ2001 Adding Reversed Numbers.入门练习题,用C语言编写. 题意简述:输入两个整数,都反转(逆序)后再求和,输出相加后反转(逆序)的结果. 问题分析:整数可能很大,大到200位:相加结果反转后左边的0需要去掉. 程序中封装了两个函数来实现,逻辑更加简单清晰. AC的C语言程序如下: /* UVA713 UVALive5539 PO

POJ 1504,ZOJ 2001,UVA 713, Adding Reversed Numbers,错误,已找到错误

------------------------------------------------------------ 以此题警告自己: 总结, 1.在数组的使用时,一定别忘了初始化 2.在两种情况复制代码时,一定要小心,注意修改变量名,一不留神就会带来不可估量的后果,一定要仔细挨着一个一个变量的修改,别跳着看着哪个变量就改哪一个变量! (这个题目中,就是复制了一下,代码,ca,我找了一下午的错....还好终于找到了,一个字母的错,) -----------------------------

zoj 2001 Adding Reversed Numbers

Adding Reversed Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. Therefore the dramatic advisor of ACM has decided to

POJ 3340 &amp; HDU 2410 Barbara Bennett&#39;s Wild Numbers(数学)

题目链接: PKU:http://poj.org/problem?id=3340 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2410 Description A wild number is a string containing digits and question marks (like 36?1?8). A number X matches a wild number W if they have the same length, and

SPOJ Python Day1: Adding Reversed Numbers

水题就要水的滴水不漏=-=,第一个疗程博主决定按照SPOJ提交人数的顺序开始刷,主要任务在于熟悉Python. 42. Adding Reversed Numbers 题目非常简单 Sample input: 3 24 1 4358 754 305 794 第一行是下面输入的行数,主要说的事儿是把第一个数反过来,第二个数反过来,然后加一起,然后再把他们的和反过来.比如说24 1 这行吧: Step 1:24 –> 42, 1 –> 1 Step 2:42+1 = 43 Step 3:43 –&

UVA 11481 - Arrange the Numbers(组合数学)

题目链接:11481 - Arrange the Numbers 题意:序列1-n,进行重排,问最后前m个中有k个仍然位置不变的情况数 思路:之前写过UVA 580, n个数重排,要求每个位置都不同的情况的题目,递推式为dp[i] = (i - 1) * (dp[i - 1] + dp[i - 2]) 利用这个,这题只要: k个位置C(m, k) * sum(C[n - m][i] (后面n-m个选出i个对应正确匹配) * dp[n - k - i](其余位置全都错排)} 这便是总情况数 代码:

zoj2001 Adding Reversed Numbers

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2001 Adding Reversed Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient pla

[LeetCode] Sum Root to Leaf Numbers(bfs)

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total sum of all root-to-leaf numbers. For example, 1 / 2 3 T

B - Adding Reversed Numbers

B - Adding Reversed Numbers Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Description The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies