IT民工
加油!

一道字符串模拟题,每行对应的是字符的ASC码参考了syhd142的写法,他的exp数组用得比较精髓。

#include<cstdio>
#include<cstdlib>
#include<cstring>

const int exp[] = { 0, 128, 64, 32, 16, 8, 0, 4, 2, 1};
char data[20];

int main()
{
while( gets( data) )
{
int ans = 0;
int len = strlen( data);
if( data[0] != '|' ) continue;
for( int i = 1; i < len - 1; i ++)
{
if( data[i] == '.') continue;
if( data[i] == 'o') ans += exp[i];
}
printf( "%c", ans);
}
return 0;
}

 

posted on 2012-01-28 17:15  找回失去的  阅读(163)  评论(0)    收藏  举报