哎,哎,哎。本来以为很简单的题,结果还是WA了一次,RE了两次。
题目看似复杂,其实本身很好理解。把' '看成0,‘o’看成1。就是二进制的ascii码。
但是,千万不要用数组储存输入,会超时。解决方法就是用getchar()一个一个读取,读满8个就putchar()出来。
还有,不能仅用换行符当作输出的判断条件。不然读到第一行和最后一行的时候会输出空字符'\0'。尤其在terminal下,空字符被隐藏起来了。在windows上的命令符貌似是一个空格。oj系统是可以识别出来的。
现在编程能力真是挫的一比啊。
题目:
"Machines take me by surprise with great frequency." |
Alan Turing
Your boss has just unearthed a roll of old computer tapes. The tapes have holes in them and might contain some sort of useful information. It falls to you to figure out what is written on them.
Input
The input will contain one tape.Output
Output the message that is written on the tape.Sample Input | Sample Output |
___________| o . o|| o . || ooo . o|| ooo .o o|| oo o. o|| oo . oo|| oo o. oo|| o . || oo . o || ooo . o || oo o.ooo|| ooo .ooo|| oo o.oo || o . || oo .oo || oo o.ooo|| oooo. || o . || oo o. o || ooo .o o|| oo o.o o|| ooo . || ooo . oo|| o . || oo o.ooo|| ooo .oo || oo .o o|| ooo . o || o . || ooo .o || oo o. || oo .o o|| o . || oo o.o || oo . o|| oooo. o || oooo. o|| o . || oo .o || oo o.ooo|| oo .ooo|| o o.oo || o. o |___________ | A quick brown fox jumps over the lazy dog. |
Problemsetter: Igor Naverniouk
Special thanks: BSD games ppt.
题解:
1 #include2 int main() 3 { 4 char c; 5 int bin=0,i=0; 6 while((c=getchar())!=EOF) 7 { 8 if(c=='\n') 9 {10 if(i==8)11 {12 putchar(bin);13 i=0;14 }15 bin=0;16 }17 else18 {19 if(c==' ')20 {21 bin=bin*2;22 i++;23 }24 else if(c=='o')25 {26 bin=bin*2+1;27 i++;28 }29 }30 }31 return 0;32 }