1493. One Step from happiness
Time limit:1.0 Second
Memory 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 of 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? Inputthe input contains the number of the ticket. The number consists of six digits, some of which can be zeros. It is guaranteed this Vova counted correctly, i.e., that the sum of the first three digits differs from the sum of the Las T three digits by one exactly. Outputoutput "Yes" if Vova is right and "No" otherwise. Samples
| input |
Output |
715068 |
Yes |
445219 |
No |
012200 |
Yes |
Notesall tram tickets has exactly six digits. A ticket is considered lucky if the sum of it first three digits equals the sum of its last three digits.
Test instructions: Determines whether the sum of the first and last three digits of a six-digit number is equal.
Analysis: Direct violence judgment can be.
AC Code:
#include <cstdio>int sum (int n) { int ans = 0; while (n) { ans + = n; n/=; } return ans;} BOOL Check (int n) { int a = n%, 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"); The previous and the latter can also be } return 0;}
URAL 1493. One Step from happiness