10878 - Decode the tape

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


其实这道题目很简单,就是每一行的内容转换为一个字符。而通过每一行是一个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;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值