uva10878(字符串)

来源:互联网 发布:淘宝买家申请售后换货 编辑:程序博客网 时间:2024/06/07 07:41

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 greatfrequency."Alan Turing

Your boss has just unearthed a roll of oldcomputer tapes. The tapes have holes in them and might contain somesort of useful information. It falls to you to figure out what iswritten 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;
   elseif(s[i]=='o')
    sum+=a[i];
  }
  printf("%c",sum);
 }
 return 0;
}