心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
将tape中的'o'变换成1,' '变换成0,'.'不用管,得到的二进制整数就是对应的字符ASCII码。
以下是我的代码:
#include<iostream>
#include
<string>
#include
<cstdio>
using namespace std;

int main()
{
    
/*
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    //
*/

    
string tape;
    getline(cin,tape);
    
while(getline(cin,tape) && tape!="___________")
    {
        
char ch(0);
        
for(int i=tape.size()-2,j=1;i>=2;i--)
        {
            
if(tape[i]=='.')
                
continue;
            
if(tape[i]=='o')
            {
                ch
+=j;
                j
*=2;
            }
            
else if(tape[i]==' ')
                j
*=2;
        }
        cout
<<ch;
    }

    
return 0;
}
posted on 2011-04-07 12:55 lee1r 阅读(292) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:字符串处理

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理