想法:
觀察a,b,c,d..字母後發現:
- a=|oo__.__o|
- b=|oo__._o_|
- c=|oo__._oo|
- d=|oo__.o__|
- e=|oo__.o_o|
可以知道它是以二進位的方式表示,在把'a'的値(2^0+2^5+2^6=97)加起來後與ASCII表比較,剛好就是表上'a'的値,因此這題把每個字元的値加起來輸出即可(換行符號它也已經在input裡囉,不用自己換行)。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
using namespace std; | |
int main() | |
{ | |
freopen ("input.txt","rt",stdin); | |
char line[50]; | |
while (gets(line)){ | |
if (line[0] != '|') continue; | |
char c = 0; | |
for (int i=0; line[i]; i++){ | |
if (line[i]==' ' || line[i]=='o') | |
c <<= 1; | |
if (line[i]=='o') | |
c++; | |
} | |
printf("%c",c); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言