当前位置: 首页 > 工具软件 > Tape > 使用案例 >

UVa10878 Decode the tape

鞠侯林
2023-12-01

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

这题大意就是要求将一串磁带的内容翻译出来,这除了头尾的每行都是以二进制ascll码表示一个字符,其中'o'代表1,' '代表0,通过计算可得出每行所代表的ascll码的十进制表示,将其输出即可。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

const int N = 20;
int main() {
	char tape[N];
	while (gets(tape)) {
		memset(tape,0,sizeof(tape));
		while (gets(tape)) {
			if (!strcmp(tape,"___________"))
				break;
			int lengthOfTape = strlen(tape);
			int ascll = 0;
			int power = 7;
			for (int i = 0; i < lengthOfTape; i++) {
				if (tape[i] == 'o') {
					ascll += pow(2,power);
					power--;
				}
				else if (tape[i] == ' ')
					power--;
			}
			printf("%c",ascll);
			memset(tape,0,sizeof(tape));
		}
	}
	return 0;
}


 类似资料:

相关阅读

相关文章

相关问答