现在的位置: 首页 > 综合 > 正文

10878 – Decode the tape

2018年04月23日 ⁄ 综合 ⁄ 共 1511字 ⁄ 字号 评论关闭

UVa OJ

Root :: AOAPC
I: Beginning Algorithm Contests (Rujia Liu)
 :: Volume
1. Elementary Problem Solving
 :: String

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

其实这道题目很简单,就是每一行的内容转换为一个字符。而通过每一行是一个2进制的ASC码值,用o与 来表示2进制中的1与0

wa了一次,多输出了空格。。要严格按照题目要求输出!

#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctype.h>
#include<algorithm>
using namespace std;
struct node
{
    char str[1000];
}word[10000];
char sen[10000];
bool cmp(node s, node v)
{
    if (strcmp(s.str,v.str)<0) return true;
    return false;
}
int main ()
{
    int t=0,i,j;
    while(gets(sen)!=NULL)
    {
        int len=strlen(sen);
        i=0,j=0;
        bool isspace=true;
        while(i<=len && len>0)
        {
            if (isalpha(sen[i])) {
                word[t].str[j++]=tolower(sen[i]);
                isspace=true;
            }
            else {
                if (isspace)
                {
                    word[t].str[j]='\0';
                    t++;
                }
                isspace=false;
                j=0;
            }
            i++;
        }
    }
    sort(word,word+t,cmp);
    for (i=0; i<t; i++)
        if (strcmp(word[i].str,word[i+1].str)!=0)
            puts(word[i].str);
    return 0;
}

抱歉!评论已关闭.