2016-07-13
UVA - 10878 Decode the tape
题目大意:解密。观察样例,每个字符有对应的一种输入。可以看出输入中点的位置是不变的,除去边界和点剩下共 7 位,空格为 0,o 为 1,前3位为16进制数,后4位为2进制数,化为十进制即对应 ascll 码。
解题思路:将输入化为 0 和 1 然后化为 ascll 码输入即可,这题主要是理解题目比较难。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char str[20];
int main () {
gets(str);
while ( gets(str) && str[0] != '_' ) {
int x[2] = {0,0};
char c = NULL;
if ( str[2] == 'o' ) x[0] += 4;
if ( str[3] == 'o' ) x[0] += 2;
if ( str[4] == 'o' ) x[0] += 1;
if ( str[5] == 'o' ) x[1] += 8;
if ( str[7] == 'o' ) x[1] += 4;
if ( str[8] == 'o' ) x[1] += 2;
if ( str[9] == 'o' ) x[1] += 1;
c = c + x[0]*16 + x[1];
cout << c ;
memset( str , '\0' , sizeof(str) );
}
return 0;
}