http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2393
中譯
http://luckycat.kshs.kh.edu.tw/homework/q11398.htm
#include "stdio.h" int main() { int str[50],num = 0,i,tmp = 0; char in[40],flag = 0; while( 1 ) { scanf(" %s",in); if( in[0] == '~' ) break; if( in[0] == '#' ) { int j = 1,out = 0; for(i = tmp - 1;i > -1;i--) { out += str[i] * j; j *= 2; } printf("%d\n",out); num = 0; tmp = 0; for(i = 0;i < 50;i++) str[i] = 0; continue; } if( strlen(in) == 1 ) flag = 1; else if( strlen(in) == 2 ) flag = 0; else { for(i = 0;i < strlen(in) - 2;i++) { str[tmp] = flag; tmp++; } } num++; } return 0; }
沒有留言:
張貼留言