Uva 12468 Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a, b;
    while(cin >> a >> b && a != -1 && b != -1)
    {
        int c1 = 0, c2 = 0, n, m;
        n = a, m = b;
        while(n != m)
        {
            if(n == 99)
            {
                c1++;
                n = 0;
            }
            else
            {
                n++;
                c1++;
            }
        }
        n = a, m = b;
        while(n != m)
        {
            if(n == 0)
            {
                c2++;
                n = 99;
            }
            else
            {
                n--;
                c2++;
            }
        }
        if(c1 < c2)
            cout << c1 << endl;
        else
            cout << c2 << endl;
    }
    return 0;
}

Comments