1. 程式人生 > >騰訊2017暑假實習筆試題-字串編碼

騰訊2017暑假實習筆試題-字串編碼

/*
騰訊2017暑假實習筆試題-字串編碼
輸入:16的倍數的字串
輸出:編碼後的結果

例子
輸入:abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl
輸出:
00000010 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 abcdefghijklmnop
00000020 71 72 73 74 75 76 77 78 79 7a 61 62 63 64 65 66 qrstuvwxyzabcdef
00000030 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 ghijklmnopqrstuv
00000040 77 78 79 7a 61 62 63 64 65 66 67 68 69 6a 6b 6c wxyzabcdefghijkl
*/
#include <iostream> #include <vector> #include <string> #include <map> using namespace std; int main() { //打表 vector<string> v(128, ""); for (int i = 'a'; i <= 'z'; ++i) { char tmp[5]; sprintf(tmp, "%02x", i); v[i] = tmp; //cout << v[i] << endl;
} int index = 0;//先列印索引部分 string in_str; cin >> in_str; while (in_str.size() >= 16) { string str = in_str.substr(0, 16); in_str = in_str.substr(16); char tmp[10]; sprintf(tmp, "%08x", index); index += 16; cout << tmp << " "
;//print index; for (auto i : str) cout << v[i] << " "; cout << str; cout << endl; } }