ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1493. One Step from Happiness

AC in c++
Posted by Yucheng 15 Feb 2019 12:48
#include<iostream>

using namespace std;
int sum(int temp);
int main(){
    int a[6];
    scanf("%1d%1d%1d%1d%1d%1d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5]);
    int first=a[0]*100+a[1]*10+a[2];
    int second=a[3]*100+a[4]*10+a[5];
    if(a[3]==9&&a[4]==9&&a[5]==9){
        cout<<"No";
        return 0;
    }
    int pre=second-1;
    int next=second+1;
    if((sum(pre)==(a[0]+a[1]+a[2]))||(sum(next)==(a[0]+a[1]+a[2]))){
        cout<<"Yes";
    }else{
        cout<<"No";
    }

return 0;
}

int sum(int temp){
    int count=0;
    do{
        count+=(temp%10);
        temp/=10;
    }while(temp/10!=0);
    count+=temp;
    return count;
}