10878 - Decode the tape

Problem A
Decode the tape
Time Limit: 1 second

"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.

本题的转换规则是:字符串中的o表示二进制的1,空格表示0,而字符'.' '|'什么也不表示应该跳过

每一行对应一串二进制代码,是一个字符的ASCII码。

OLE了一次 说输出冗余信息。后来打印了每次的输出发现字符串的最后跟着两个ASCII码为2的字符。是两个控制字符,文始。修改了一下就AC了

AC代码如下:

#include <stdio.h>

int main(void)
{
	int i, j;
	int len, temp;
	char buf[20];
	char s[200];
	
	while (fgets(buf, 20, stdin) != NULL) {
		temp = 0;
		if (buf[0] == '_')
			continue;
		for (i = 1; i < 10; ++i) {
			if (buf[i] == 'o')
				temp = temp * 2 + 1;
			else if (buf[i] == ' ')
				temp *= 2;
		}
		
		if (temp != 2) 		
			putchar(temp);
	}

	return 0;
}


你可能感兴趣的:(null,OO,input,output)