Uva - 10878 - Decode the tape

来源:互联网 发布:网络电视iptv设置 编辑:程序博客网 时间:2024/05/10 15:25

题意:给出一个图,从中译码。

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=1819

——>>‘o’为1,空格为0,‘.’不理,构成一个七位的二进制数,对应的ASCII码的字符即是答案。

#include <iostream>using namespace std;int main(){    char s[15];    while(cin.getline(s, sizeof(s)))    {        if(s[0] == '|')        {            char c = 0;            for(int i = 2; i <= 5; i++)                if(s[i] == 'o') c = c * 2 + 1;                else c *= 2;            for(int i = 7; i <= 9; i++)                if(s[i] == 'o') c = c * 2 + 1;                else c *= 2;            cout<<c;        }    }    return 0;}


原创粉丝点击