Contest 3:Problem A: Number and its reverse
来源:互联网 发布:linux 查看函数头文件 编辑:程序博客网 时间:2024/06/06 16:35
此题注意c中无reverse函数,用模的方法进行reverse操作。计算反转数时忘注意回文数,导致了最开始想减小计算域,结果从1开始也不会超时。C'est tout.
Description
Give you a number M (9999<=M<=9999999).
Output the number of total numbers such that the sum of this number and its reverse is M.
Input
There are several lines. And each line contains a positive number M (9999<=M<=9999999).
Output
Output the number of total numbers such that the sum of this number and its reverse is M.
Output 0 if there is no such numbers.
For example,
Input
1333
2444
Output
6
0
Because 419, 518, 617, 716, 815, 914 are total numbers such that the sum of this number and its reverse is 1333. (419+914=1333)
Sample Input
13332444
Sample Output
60
HINT
#include <stdio.h>#include <stdlib.h>int reverse(int x){ int r = 0; while(x) { r=r*10+x%10; x/=10; } return r;}int main(){ int n,j,i,num; while (scanf("%d",&n)!=EOF){ num=0; for(i=1;i<=n;i++){ j=reverse(i); if(n==j+i) num+=1; } printf("%d\n",num);} return 0;}
阅读全文
0 0
- Contest 3:Problem A: Number and its reverse
- Reverse a positive number
- contest: Codeforces Round #307 (Div. 2), problem: (A) GukiZ and Contest
- A. GukiZ and Contest
- codeforces/contest/797/problem/A
- Reverse a string and reverse a sentence
- A. Alex and broken contest
- A. Alex and broken contest
- http://codeforces.com/contest/6/problem/A
- http://codeforces.com/contest/7/problem/A
- http://codeforces.com/contest/1/problem/A
- Problem A. Read Phone Number
- Problem A. Read Phone Number
- UVa Problem Solution: 10018 - Reverse and Add
- a letter and a number
- a letter and a number
- a letter and a number
- a letter and a number
- TypeError: 'method' object is not subscriptable
- 算法之插入排序
- 二叉树深度优先搜索(DFS)、广度优先搜索(BFS)
- 反转加密与凯撒加密 python实现
- fdsfds
- Contest 3:Problem A: Number and its reverse
- 文件上传----不使用submit提交
- 并查集解1335 : Email Merge(hihocoder)
- C语言学习笔记(五)——复合类型
- 算法之选择排序
- ECLIPSE生成JAVADOC时出错:编码GBK的不可映射字符
- 回车事件
- HDU4670-Cube number on a tree
- hdu 2639 (Bone Collector II) 0-1背包的第k优解