题目:
"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
___________
| 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 |
___________
sample output
A quick brown fox jumps over the lazy dog.
题解:‘o’代表 1, ‘ ’代表 0,其他字符无意义,转换成二进制计算ASCII值得到文本。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int s[8], flag;
int a[8] = {128, 64, 32, 16, 8, 4, 2, 1};
void fun(){
int ans = 0, i;
for (i = 0; i < 8; i++)
ans += a[i] * s[i];
char k = ans;
cout << k;
flag = 0;
}
int main(){
char c;
while(1){
c = getchar();
if(c == '\n')
break;
}
while(1){
scanf("%c", &c);
if (c == ' ' && flag < 8)
s[flag++] = 0;
else if (c == 'o' && flag < 8)
s[flag++] = 1;
else if (flag == 8)
fun();
else if (c == '_')
return 0;
else
continue;
}
return 0;
}