The question is very simple and the code is very short. At the first time, I almost ignored the small box in the input, so wa once.
Each line represents a binary ASCII code, 'O' represents 1, space represents 0, and small black spots in the middle are ignored.
I directly read a line of strings. If the string starts with an underscore, the input ends (the processing of the string starts from line 1 ).
Then, one character from left to right is judged as a space directly * 2, which is 'O' first * 2 and then 1. Finally, the corresponding ASCII value is calculated.
Problem
Decode the tape
Time Limit: 1 second
"Machines take me by surprise with great frequency ." |
Alan Turing
Your boss has just uneared 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 //#define LOCAL 2 #include <iostream> 3 #include <cstring> 4 #include <cstdio> 5 using namespace std; 6 7 int main(void) 8 { 9 #ifdef LOCAL10 freopen("10878in.txt", "r", stdin);11 #endif12 int i;13 char str[15], ascii;14 gets(str);15 while(gets(str) && str[0] != ‘_‘)16 {17 ascii = 0;18 for(i = 0; i < strlen(str); ++i)19 {20 if(str[i] == ‘ ‘)21 ascii *= 2;22 if(str[i] == ‘o‘)23 {24 ascii *= 2;25 ascii += 1;26 }27 }28 printf("%c", ascii);29 }30 return 0;31 }
Code Jun