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

#include <iostream>
#include <string>
using namespace std;
int main(){
    int m=131071;
    while(!cin.eof()){
        int x=1,ans=0;
        char c;
        string s;
        ws(cin);
        while(cin>>c){
            ws(cin);
            if(!(c=='0'||c=='1'))
                break;
            s.push_back(c);
        }
        for(int i=s.size()-1;i>=0;i--){
            if(s[i]=='1'){
                ans+=x;
                ans%=m;
            }
            x<<=1;
            x%=m;
        }
        if(ans)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
}

Comments