uva10878(字符串)

本文解析了一道计算机竞赛题目“解码磁带”,介绍了如何通过读取特殊格式的磁带输入并将其转换为字符信息的过程。文章提供了一个C语言实现的例子,展示了如何根据磁带上孔洞的排列来解码出隐藏的消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

10878 - Decode the tape

Time limit: 3.000 seconds

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.

 

题意:其实就是二进制相关的计算。'o'表示1,' '(空格)表示0比如第一组数据

  o| 一共有8位,不包括'|'和'.'那么就算的值就是2的6次方+2的0次方=65对应的字母是'A'..

知道怎么做就是卡。还是要加大代码量啊 

 

#include<stdio.h>
#include<string.h>
int main()
{
 char s[20];
 int a[]={0,128,64,32,16,8,0,4,2,1};
 int i,sum;
 while(gets(s))
 {
  if(s[0]!='|')
   continue;
  int len=strlen(s);
  sum=0;
  for(i=1;i<len-1;i++)
  {
   if(s[i]=='.')
    continue;
   else if(s[i]=='o')
    sum+=a[i];
  }
  printf("%c",sum);
 }
 return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值