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

whats wrong with this code?it say wrong answer
Posted by sina roozegar 22 Nov 2017 21:34
#include<iostream>
using namespace std;

int main()
{
    int x, y;
    int sum1 = 0, sum2 = 0;
    char n = 'n';

    cin >> x;
    int max = x + 1;
    int min = x - 1;
    for (int i = 0; i <3; i++)
    {
        y = max % 10;

        max = max / 10;
        sum1 += y;
    }
    for (int i = 0; i < 3; i++)
    {
        y = max % 10;

        max = max / 10;
        sum2 += y;

    }
    if (sum2 == sum1)
    {
        n = 'y';

    }

    y = 0;
    sum1 = 0;
    sum2 = 0;
    for (int i = 0; i <3; i++)
    {
        y = min % 10;

        min = min / 10;
        sum1 += y;
    }
    for (int i = 0; i <3; i++)
    {
        y = min % 10;

        min = min / 10;
        sum2 += y;
    }
    if (sum2 == sum1)
    {
        n = 'y';

    }
    if (n=='n')
    {
        cout << "no";
    }
    else
    {
        cout << "yes";
    }
    return 0;
}