POJ 1504 Adding Reversed Numbers(字符串巧解)
来源:互联网 发布:netbeans for php下载 编辑:程序博客网 时间:2024/05/18 02:00
原题
Adding Reversed Numbers
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
Description
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 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
题意
求两数字反转之和的反转
例:24-〉42 1-〉1 42+1=43 43-〉34
涉及知识及算法
水题,仅需要字符串基本知识,但考察细节。
巧解:利用字符串库函数strrev(),(非标准函数)。需要头文件#include <string.h>。编译器GCC。
代码
附上POJ yyii1111的代码
#include <stdio.h>#include <string.h>char str[100];int main() { int n, a, b; scanf("%d%*c", &n); while(n--) { gets(str); sscanf(strrev(str), "%d%d", &a, &b); sprintf(str, "%d", a + b); sscanf(strrev(str), "%d", &a); printf("%d\n", a); } return 0;}向他表示感谢。
- POJ 1504 Adding Reversed Numbers(字符串巧解)
- poj 1504 Adding Reversed Numbers
- poj 1504 Adding Reversed Numbers
- POJ 1504 adding reversed numbers
- POJ 1504 Adding Reversed Numbers
- POJ 1504 Adding Reversed Numbers
- POJ 1504 Adding Reversed Numbers
- POJ 1504:Adding Reversed Numbers
- poj 1504 Adding Reversed Numbers(简单字符串的处理)
- poj 1504 Adding Reversed Numbers【反转数字】
- POJ 1504 Adding Reversed Numbers(水~)
- 1504 Adding Reversed Numbers
- pku 1504 Adding Reversed Numbers
- PKU 1504 Adding Reversed Numbers
- POJ 1504 Adding Reversed Numbers…
- Poj 1504 Adding Reversed Numbers(用字符串反转数字)
- POJ-1504 Adding Reversed Numbers-逆序数相加
- POJ 1504 Adding Reversed Numbers 已被翻译
- 从键盘输入某个十进制小数或整数,转换成对应的二进制小数并输出。 (查询十进制小数转换成二进制小数的算法,使用循环来实现。 最多保留小数位后7位数字即可)算法
- hdu 2021 发工资咯:)贪心
- 什么是VBI
- Futexes Are Tricky
- 170715 如何更改CSDN上传图片大小
- POJ 1504 Adding Reversed Numbers(字符串巧解)
- CentOS7的网卡设置
- 关于SEO(搜索引擎优化)的个人掌握知识分享
- 从删除邮件小页面看flag标志位
- java线程中断,interrupt()方法的一些示例
- 组合和继承
- POJ_1573
- bzoj 3879: SvT
- Neo4j安装&入门&一些优缺点