將tape中的'o'變換成1,' '變換成0,'.'不用管,得到的二進(jìn)制整數(shù)就是對(duì)應(yīng)的字符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 閱讀(328)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
題目分類:字符串處理