UVa10878_Decode the tape(小白书字符串专题)

来源:互联网 发布:linux下mysql安装教程 编辑:程序博客网 时间:2024/05/22 15:58

Description


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.


解题报告

第一眼不懂,第二眼略懂,第三眼水题。。。

有个地方需要注意,就是输入和输出的地方,可以定义数组输入,每次输入类似| o   .  o|
返回一个字符,其实'|','.','_'都不用考虑,只要考虑'o'的情况。

每次输入的数组好像都是11个字符大小的,除第一行和最后一行外第一个和最后一个恒为'|',第七字符恒为'.',这样就可以定义一个大小为12的字符数组。

#include<stdio.h>  int main()  {      char str[12];      int i,n;      while(gets(str)!=NULL)      {          if(str[0]=='_')          continue;          n = 0;          for (i=2;i<=9;i++)          {              if(str[i]=='o')                  switch(i)                  {                      case 2:n=n+64;break;                      case 3:n=n+32;break;                      case 4:n=n+16;break;                      case 5:n=n+8;break;                      case 7:n=n+4;break;                      case 8:n=n+2;break;                      case 9:n=n+1;break;                  }          }          putchar(n);      }      return 0;  }


0 0
原创粉丝点击