UVa 10176 - Ocean Deep! - Make it shallow!!

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int number=0 , p = 131071;
    char ch;

    while(cin >> ch)
    {
        if(ch=='#')
        {
            if(number)
            {
                cout << "NO\n";
            }

            else
            {
                cout << "YES\n";
            }

            number = 0;
            continue;
        }

        number = (number * 2) + (ch-48); // make a number from binary to decimal
        number%=p;
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number