URAL 1493. One Step from happiness

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.