现在的位置: 首页 > 综合 > 正文

UVa 10878 – Decode the tape

2013年04月05日 ⁄ 综合 ⁄ 共 341字 ⁄ 字号 评论关闭

题目:破译编码。

分析:简单题、编码。仔细观察发现规律,‘o’代表1,‘ ’带表0,‘:’无视;然后转换成二进制,按ASC码输出字符即可。

注意:没有换行。一个回车引发的血案。

#include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

int value[11] = {0,0,64,32,16,8,0,4,2,1,0};

int main()
{
	char buf[12];
	gets(buf);
	while ( gets(buf) && buf[0] != '_' ) {
		int sum = 0;
		for ( int i = 2 ; i < 10 ; ++ i )
			if ( buf[i] == 'o' )
				sum += value[i];
		printf("%c",sum);
	}
	return 0;
}

抱歉!评论已关闭.