本文主要是介绍uva 10878 Decode the tape,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
这道题可以算一道入门题,不需要用什么算法。
首先是理解题意,如果你把纸条的8个位置(点前有5个位置,不是4个,点后有3个位置)对应到char类型的8个位置上去,可以发现那正好是输出字符的ASC II码。
其次,要注意题目说了只有一个纸带,并且‘_’和‘|’也要处理。
最后,谈一下我犯的错误,就是没有把输入全部读取,而是在判断到‘\n’时就退出,导致WA,所以下次不管需不需要把输入全部读完才能得出答案,都得把输入读完。
由于输入十分繁琐,所以用输入输出流转向的方法,将标准输入输出转到文件读取写入。
代码(C++11):
#include <cstdlib>
#include <iostream>
//#define LOCAL
using namespace std;int main(int argc, char *argv[])
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif char line[15],ch,t;int i,j=0;while(cin.getline(line,15)){ if('_'==line[0]) continue; ch=0; for(i=1;i<10;i++){ if('o'==line[i]){t=1;if(i<6) t<<=8-i;else t<<=9-i;ch|=t;} }cout<<ch; //if(ch=='\n') break; } system("PAUSE");return EXIT_SUCCESS;
}
原题:
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. |
这篇关于uva 10878 Decode the tape的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!