您的位置:首页 > 其它

UVa10878 - Decode the tape-字符串-难度1

2013-12-23 13:04 441 查看
题目链接:

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1819

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.
代码+思路:

/*
*主要是理解题意:
*去除'.',其余7位组成ASCII码,'o'表示对应位是1
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
const int MAX = 101;
char ans[MAX][MAX];
int main()
{
#ifdef LOCAL
freopen("f:\\input.txt", "r", stdin);
//freopen("f:\\output.txt", "w", stdout);
#endif
string s;
int first = 0;
while(getline(cin, s))
{
if(s[0] == '_')
{
if(first == 1)
{
cout << endl;
break;
}
else
{
continue;
}
}
int sum = 0;
int time = 1;
for(int i = 9; i != 1; i--)
{
if(s[i] == 'o')
{
sum += time;
}
if(s[i] != '.')//如果是'.', 跳过这位
time = 2 * time;
}
printf("%c", sum);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: