URAL 1493. One Step from Happiness
2015-03-09 17:33
260 查看
1493. One Step from Happiness
Time limit: 1.0 secondMemory limit: 64 MB
Vova bought a ticket in a tram of the 13th route and counted the sums of the first three and the last three digits of the ticket's number (the number has six digits). It turned out that the sums differed
by one exactly. "I'm one step from happiness," Vova thought, "either the previous or the next ticket is lucky." Is he right?
Input
The input contains the number of the ticket. The number consists of six digits, some of which can be zeros. It is guaranteed that Vova counted correctly, i.e., that the sum of the first three digitsdiffers from the sum of the last three digits by one exactly.
Output
Output "Yes" if Vova is right and "No" otherwise.Samples
input | output |
---|---|
715068 | Yes |
445219 | No |
012200 | Yes |
Notes
All tram tickets have exactly six digits. A ticket is considered lucky if the sum of its first three digits equals the sum of its last three digits.题意:判断六位数字的的前,后三位数字之和是否相等。
解析:直接暴力判断即可。
AC代码:
#include <cstdio> int sum(int n){ int ans = 0; while(n){ ans += n % 10; n /= 10; } return ans; } bool check(int n){ int a = n % 1000, b = n / 1000; return sum(a) == sum(b); } int main(){ #ifdef sxk freopen("in.txt", "r", stdin); #endif //sxk int n; while(scanf("%d", &n)==1){ puts(check(n) || check(n-1) || check(n+1) ? "Yes" : "No"); //前一个和后一个也可以 } return 0; }
相关文章推荐
- one from ural
- One-Step Change from Baseline Calculations
- one difference of python3 from python
- [转]how to inserting multiple rows in one step
- BAPI to Copy Materials from one Plant to Another
- STEP BY STEP RMAN DUPLICATE Database From RAC ASM To RAC ASM (Doc ID 1913937.1)
- Top Ten One-Liners from CommandLineFu Explained
- org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property
- ABAP to copy aggregates from one cube to another
- (Step one)利用JAVA进行XML编程
- Caused by: java.sql.SQLException: Io 异常: Got minus one from a read call
- attempted to assign id from null one-to-one
- ORA-16796: one or more properties could not be imported from the database [ID 358040.1]
- You Are the One(区间dp)(fromHDU)
- copy from one array to another
- One Day One Step 之全错位排序
- How To Clone A Database Home From One Server To Other(same SID,directory,path)
- Got minus one from a read call的解决方法
- This Style does not belong to the supplied Workbook. Are you trying to assign a style from one workb
- BAPI to Copy Materials from one Plant to Another