UVa 10878 Decode the tape

题目很简单,代码也很短。第一遍做的时候,我居然二乎乎的把input里面的小框框忽略掉了,大哭,所以WA了一次。

每一行代表一个二进制的ASCII码,'o'代表1,空格代表0,中间的小黑点忽略。

我直接把一行字符串全读进去,如果字符串以下划线开头说明输入结束(字符串的处理从第2行开始)。

然后从左到右一个字符一个字符的判断,是空格直接*2,是'o'先*2后加1,最后算出的就是对应的ASCII值。

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.


//#define LOCAL
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int main(void)
{
	#ifdef LOCAL
		freopen("10878in.txt", "r", stdin);
	#endif
	int i;
	char str[15], ascii;
	gets(str);
	while(gets(str) && str[0] != '_')
	{
		ascii = 0;
		for(i = 0; i < strlen(str); ++i)
		{
			if(str[i] == ' ')
				ascii *= 2;
			if(str[i] == 'o')
			{
				ascii *= 2;
				ascii += 1;
			}
		}
		printf("%c", ascii);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值