ACM Adding Reversed Numbers(summer2017)
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
3
24 1
4358 754
305 794
Sample Output
34
1998
1
/*
author:WTZPT
Time:2017.7.17
Title:Adding Reversed Numbers
*/
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
int length(int num){ //测试数据长度
int i = ;
while(num){
num /= ;
i++;
}
return i;
} int trans(int num ,int len){
int temp,sum;
sum = ;
while(num){
temp = num % ;
sum += temp*((int)pow(10.0,(len-)*1.0));
num /= ;
len--; }
return sum;
}
int main()
{
int n,num1,num2,len1,len2,sum1,sum2,sum,len3,num;
while(cin>>n){
for(int ii = ; ii < n; ii++)
{
sum = ;
scanf("%d %d",&num1,&num2);
len1 = length(num1); //数据长度
len2 = length(num2);
//cout<<len1<<" "<<len2<<endl; 测试获取长度函数
sum1 = trans(num1,len1);//获得转化后数
sum2 = trans(num2,len2);
//cout<<sum1<<" "<<sum2<<endl; 测试第一次转化
sum = sum1 + sum2;
len3 = length(sum);
num = trans(sum,len3);
cout<<num<<endl;
} }
return ;
}
参考:
http://blog.csdn.net/shiow1991/article/details/7220318
ACM Adding Reversed Numbers(summer2017)的更多相关文章
- zoj 2001 Adding Reversed Numbers
Adding Reversed Numbers Time Limit: 2 Seconds Memory Limit: 65536 KB The Antique Comedians of M ...
- poj1504 Adding Reversed Numbers
Adding Reversed Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17993 Accepted: 9 ...
- Humble Numbers(hdu1058)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- zoj2001 Adding Reversed Numbers
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2001 Adding Reversed Numbers Time ...
- 【CF55D】Beautiful numbers(动态规划)
[CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...
- ACM博弈知识汇总(转)
博弈知识汇总 有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍或是围棋子等等均可.两个人轮流从堆中取物体若干,规定最后取光物体者取胜.这是我国民间很古老的一个游戏,别看这游戏极其简单,却蕴含着深刻 ...
- 一位ACM过来人的心得(转)
励志下! 刻苦的训练我打算最后稍微提一下.主要说后者:什么是有效地训练? 我想说下我的理解.很多ACMer入门的时候,都被告知:要多做题,做个500多道就变牛了.其实,这既不是充分条件.也不会是必要条 ...
- Round Numbers(组合数学)
Round Numbers Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Tota ...
- PAT 甲级 1023 Have Fun with Numbers(20)(思路分析)
1023 Have Fun with Numbers(20 分) Notice that the number 123456789 is a 9-digit number consisting exa ...
随机推荐
- python CSRF跨站请求伪造
python CSRF跨站请求伪造 <!DOCTYPE html> <html lang="en"> <head> <meta chars ...
- 南阳OJ-14-会场安排问题---区间不相交
题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=14 题目描述: 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突 ...
- 属性添加get和set方法
出错信息: Struts Problem Report Struts has detected an unhandled exception: Messages: File: com/myHibern ...
- 计蒜客NOIP模拟赛4 D2T1 鬼脚图
鬼脚图,又称画鬼脚,在日本称作阿弥陀签,是一种经典游戏,也是一种简易的决策方法,常常用来抽签或决定分配组合. 下图就是一张鬼脚图,其包含若干条竖线和若干条横线.请注意,横线只能水平连接相邻的两条竖线, ...
- 【BZOJ3573】【HNOI2014】米特运输
Description 米特是D星球上一种非常神秘的物质,蕴含着巨大的能量.在以米特为主要能源的D星上,这种米特能源的运输和储存一直是一个大问题. D星上有N个城市,我们将其顺序编号为1到N,1号城市 ...
- ●HDU 5608 function
题链: http://acm.hdu.edu.cn/showproblem.php?pid=5608 题解: 莫比乌斯反演,杜教筛 已知$$N^2-3N+2=\sum_{d|N} f(d)$$ 多次询 ...
- 洛谷P3164 [CQOI2014]和谐矩阵
高斯消元,可以直接消的 #include<cstdio> #include<cstdlib> #include<algorithm> #include<cst ...
- ●BZOJ 2329 [HNOI2011]括号修复.cpp
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2329 题解: Splay 类似 BZOJ 2329 [HNOI2011]括号修复 只是多了一 ...
- linux内核中的链表
1.内核中的链表 linux内核链表与众不同,他不是把将数据结构塞入链表,而是将链表节点塞入数据,在2.1内核中引入了官方链表,从此内核中所有的链表使用都采用此链表,千万不要在重复造车轮子了!链表实现 ...
- 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering
Problem Description Bob's school has a big playground, boys and girls always play games here after s ...