给出两个已经反转了的整数,如何求得原数相加之后的反转的数呢?
其中有去零的要求,可以看题:
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 transfigure some tragedies into comedies. Obviously, this work is very hard because
the basic sense of the play must be kept intact, although all the things change to their opposites. For example the numbers: if any number appears in the tragedy, it must be converted to its reversed form before being accepted into the comedy play.
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 ofNcases (equal to about 10000). The first line of the input contains only positive integerN. 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.
Example
Sample input:
3
24 1
4358 754
305 794
Sample output:
34
1998
1
会反正整数的基础就好办了, 那么本题就是多次反正整数了,注意要使用longlong,因为反转整数的时候也有可能溢出的。
看看如何反正整数吧:
#pragma once
#include <iostream>
#include <vector>
#include <string>
using namespace std;
long long revs(long long a)
{
long long b = 0;
while (a)
{
b = b * 10 + a % 10;
a /= 10;
}
return b;
}
void AddingReversedNumbers()
{
long long a = 0, b = 0;
int T = 0;
cin>>T;
while (T--)
{
cin>>a>>b;
a = revs(a) + revs(b);
cout<<revs(a)<<endl;
}
}
分享到:
相关推荐
Some Solution of Problem in SPOJ (Sphere Online Judge) solved in various algorithm.
My solution for some spoj problems
我已解决的SPOJ问题的解决方案。 仅当您自己尝试过该问题并且无法提出任何解决方案,也可以随意报告任何错误并为该存储库提供解决方案时,才请参考这些解决方案。 我的个人资料链接 会费 分叉仓库并为新添加的解决...
SPOJ-Solutions:SPOJ算法问题的解决方案
RandomGoCode:算法,SPOJ,涂鸦...但是在Go中!
SPOJ-备份工具 介绍 在 Sphere Online Judge ( ) 中,您可以尝试所给的具有挑战性的问题。 它还使您能够查看和下载您自己的解决方案。 工具 SPOJ_BACKUP 备份所有已接受的提交并将它们保存在脚本所在的计算机位置。...
SPOJ-解决方案SPOJ问题的解决方案,主要是java一些python。
) :red_heart:附Oj平台平台地址BZOJ POJ 硬盘单元洛谷 代码VS 牛编码器 LibreOJ 编码部队 51点头 编码器 上海交大 最佳编码器 卢特斯 华东师范大学 SPOJ 宁波奥杰 Darkbzoj 虚拟法官 上下文猎人 维霍斯 公开评委小...
SPOJ-解决方案复合解决方案
Spoj-解决方案 此存储库包含 spoj 问题的解决方案。 问题是通过他们的 id 来识别的。
Spoj-解决方案 我的连接解决方案
SPOJ题库( http://www.spoj.pl)的离线题库。 包括索引+内容。PDF格式。 主要是Classical的problemset。
Spoj 用户工具基于 Django 的 Spoj 用户分析工具。 目前托管在 Google Appengine 上: ://spojtool.appspot.com/安装获取列出的包,并将它们放在指定的项目目录中。 为了安全,请修改 secret_key.py 中的 SECRET_KEY...
SPOJ解决方案 最好的:我的SPOJ
Judge-允许使用各种各样的编程语言【SPOJ】 http://www.spoj.pl/ SGU Online Contester-具有模拟参加历史比赛的虚拟赛功能 http://acm.sgu.ru/ Codeforces-不断维护历届题库 http://codeforces.com 首先,...
复合溶液简单的CONNECT问题的解决方案。 参见: :
我在C ++中针对Spoj托管的一些问题的解决方案 :laptop: 编码BUGLIFE 埃及披萨丽莎NFURY PT07Y TRT 地址BVAAN EKO LPIS 纽约10E PT07Z TWENDS 阿格罗夫CAM5 电动车MAIN12A ORDSUM23 里瓦尔斯ULM09 爱宝CODERE3 前脸...
SPOJ 应对spoj.com的挑战
spoj reverse 的solution
SPOJ调整在SPOJ网站上进行细微调整的Chrome扩展程序,在很大程度上基于的先前工作进行了调整,以适应网站的新布局。特征经典问题在问题集中的“用户”列旁边有一个“分数”列。 点数显示在经典问题的标签下,挑战...