URAL 1493. One Step from Happiness

來源:互聯網
上載者: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 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?InputThe 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 digits differs from the sum of the last 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 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;}




URAL 1493. One Step from Happiness

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.