uva 10878 - Decode the tape

#include<iostream>
#include<cctype>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
/*
每行'o'表示1,' '表示0,二进制转换为十进制是ASCII码
*/
int main(){
    string s;
    getline(cin,s);
    while(getline(cin,s)){
        if(s[0] == '_')
            break;
        int num = 0;
        for(int i = 2; i< s.length() - 1; i++){
            if(s[i] == 'o')
                num = num * 2 + 1;
            else if(s[i] == ' ')
                num = num * 2;
        }
        cout << (char)num;
    }

    return 0;
}

 

posted @ 2015-07-16 13:56  杨永华  阅读(113)  评论(0编辑  收藏  举报