UVa 10878 - Decode the tape Solution

#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
    string s,ans;
    cin>>s;
    while(getline(cin,s)){
        int c=0,p=1;
        int i=9;
        while(i>6){
            if(s[i]=='o')
                c+=p;
            p*=2;
            i--;
        }
        i--;
        while(i>0){
            if(s[i]=='o')
                c+=p;
            p*=2;
            i--;
        }
        if(c&&c!=13)
            ans.push_back(c);
        else if(c==13)
            ans.push_back(10);
    }
    cout<<ans;
}

Comments