The Code A Doctor Loved
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0088
解法:やるだけ
今回、mapのinsert分をいくつも書くのがダルかったので、C++でコピペ出来るように作成。
test_input.txtでこんなん用意してから、
101 ' 000000 , 000011 - 10010001 . 010001 ? 000001 A 100101 B 10011010 C 0101 D 0001 E 110 F 01001 G 10011011 H 010000 I 0111 J 10011000 K 0110 L 00100 M 10011001 N 10011110 O 00101 P 111 Q 10011111 R 1000 S 00110 T 00111 U 10011100 V 10011101 W 000010 X 10010010 Y 10010011 Z 10010000
これを実行すると、
#include<iostream> #include <fstream> #include<string> using namespace std; int main() { ifstream cin("test_input.txt"); ofstream cout("test_out.txt"); string s; while (cin >> s) { cout << "hoge.insert( map<string, string>::value_type("; cout << '"' + s + '"' + ','; cin >> s; cout << '"' + s + '"'; cout << "));" << endl; } }
こんなん出てきます。
hoge.insert( map<string, string>::value_type(" ","101")); hoge.insert( map<string, string>::value_type("'","000000")); hoge.insert( map<string, string>::value_type(",","000011")); hoge.insert( map<string, string>::value_type("-","10010001")); hoge.insert( map<string, string>::value_type(".","010001")); hoge.insert( map<string, string>::value_type("?","000001")); hoge.insert( map<string, string>::value_type("A","100101")); hoge.insert( map<string, string>::value_type("B","10011010")); hoge.insert( map<string, string>::value_type("C","0101")); hoge.insert( map<string, string>::value_type("D","0001")); hoge.insert( map<string, string>::value_type("E","110")); hoge.insert( map<string, string>::value_type("F","01001")); hoge.insert( map<string, string>::value_type("G","10011011")); hoge.insert( map<string, string>::value_type("H","010000")); hoge.insert( map<string, string>::value_type("I","0111")); hoge.insert( map<string, string>::value_type("J","10011000")); hoge.insert( map<string, string>::value_type("K","0110")); hoge.insert( map<string, string>::value_type("L","00100")); hoge.insert( map<string, string>::value_type("M","10011001")); hoge.insert( map<string, string>::value_type("N","10011110")); hoge.insert( map<string, string>::value_type("O","00101")); hoge.insert( map<string, string>::value_type("P","111")); hoge.insert( map<string, string>::value_type("Q","10011111")); hoge.insert( map<string, string>::value_type("R","1000")); hoge.insert( map<string, string>::value_type("S","00110")); hoge.insert( map<string, string>::value_type("T","00111")); hoge.insert( map<string, string>::value_type("U","10011100")); hoge.insert( map<string, string>::value_type("V","10011101")); hoge.insert( map<string, string>::value_type("W","000010")); hoge.insert( map<string, string>::value_type("X","10010010")); hoge.insert( map<string, string>::value_type("Y","10010011")); hoge.insert( map<string, string>::value_type("Z","10010000"));
ここで、スペースの部分は自分で全角から半角にするのを忘れない!!
これを符号から文字にするものも同じように作成する。
それでこれが最終的なコード
#include<iostream> #include<string> #include<map> using namespace std; int main() { map<string, string> hoge; map<string, string> hoge2; hoge.insert( map<string, string>::value_type(" ","101")); hoge.insert( map<string, string>::value_type("'","000000")); hoge.insert( map<string, string>::value_type(",","000011")); hoge.insert( map<string, string>::value_type("-","10010001")); hoge.insert( map<string, string>::value_type(".","010001")); hoge.insert( map<string, string>::value_type("?","000001")); hoge.insert( map<string, string>::value_type("A","100101")); hoge.insert( map<string, string>::value_type("B","10011010")); hoge.insert( map<string, string>::value_type("C","0101")); hoge.insert( map<string, string>::value_type("D","0001")); hoge.insert( map<string, string>::value_type("E","110")); hoge.insert( map<string, string>::value_type("F","01001")); hoge.insert( map<string, string>::value_type("G","10011011")); hoge.insert( map<string, string>::value_type("H","010000")); hoge.insert( map<string, string>::value_type("I","0111")); hoge.insert( map<string, string>::value_type("J","10011000")); hoge.insert( map<string, string>::value_type("K","0110")); hoge.insert( map<string, string>::value_type("L","00100")); hoge.insert( map<string, string>::value_type("M","10011001")); hoge.insert( map<string, string>::value_type("N","10011110")); hoge.insert( map<string, string>::value_type("O","00101")); hoge.insert( map<string, string>::value_type("P","111")); hoge.insert( map<string, string>::value_type("Q","10011111")); hoge.insert( map<string, string>::value_type("R","1000")); hoge.insert( map<string, string>::value_type("S","00110")); hoge.insert( map<string, string>::value_type("T","00111")); hoge.insert( map<string, string>::value_type("U","10011100")); hoge.insert( map<string, string>::value_type("V","10011101")); hoge.insert( map<string, string>::value_type("W","000010")); hoge.insert( map<string, string>::value_type("X","10010010")); hoge.insert( map<string, string>::value_type("Y","10010011")); hoge.insert( map<string, string>::value_type("Z","10010000")); hoge2.insert( map<string, string>::value_type("00000","A")); hoge2.insert( map<string, string>::value_type("00001","B")); hoge2.insert( map<string, string>::value_type("00010","C")); hoge2.insert( map<string, string>::value_type("00011","D")); hoge2.insert( map<string, string>::value_type("00100","E")); hoge2.insert( map<string, string>::value_type("00101","F")); hoge2.insert( map<string, string>::value_type("00110","G")); hoge2.insert( map<string, string>::value_type("00111","H")); hoge2.insert( map<string, string>::value_type("01000","I")); hoge2.insert( map<string, string>::value_type("01001","J")); hoge2.insert( map<string, string>::value_type("01010","K")); hoge2.insert( map<string, string>::value_type("01011","L")); hoge2.insert( map<string, string>::value_type("01100","M")); hoge2.insert( map<string, string>::value_type("01101","N")); hoge2.insert( map<string, string>::value_type("01110","O")); hoge2.insert( map<string, string>::value_type("01111","P")); hoge2.insert( map<string, string>::value_type("10000","Q")); hoge2.insert( map<string, string>::value_type("10001","R")); hoge2.insert( map<string, string>::value_type("10010","S")); hoge2.insert( map<string, string>::value_type("10011","T")); hoge2.insert( map<string, string>::value_type("10100","U")); hoge2.insert( map<string, string>::value_type("10101","V")); hoge2.insert( map<string, string>::value_type("10110","W")); hoge2.insert( map<string, string>::value_type("10111","X")); hoge2.insert( map<string, string>::value_type("11000","Y")); hoge2.insert( map<string, string>::value_type("11001","Z")); hoge2.insert( map<string, string>::value_type("11010"," ")); hoge2.insert( map<string, string>::value_type("11011",".")); hoge2.insert( map<string, string>::value_type("11100",",")); hoge2.insert( map<string, string>::value_type("11101","-")); hoge2.insert( map<string, string>::value_type("11110","'")); hoge2.insert( map<string, string>::value_type("11111","?")); string s; while (getline(cin , s)) { string s_to_hoge = ""; for (int i=0; i < s.size(); i++) { string h = ""; h += s[i]; s_to_hoge += hoge[h]; //cout << hoge[h] << endl; } //cout << s_to_hoge << endl; while (s_to_hoge.size() % 5 != 0) { s_to_hoge += "0"; } //cout << s_to_hoge << endl; string result = ""; for (int i=0; i < s_to_hoge.size(); i+=5) { string ss = ""; //cout << s_to_hoge[i] << endl; for (int j=i; j < i+5; j++) { ss += s_to_hoge[j]; } result += hoge2[ss]; //cout << ss << endl; } cout << result << endl; } }
簡単だね