1 /* 2 normalize prefix 3 */ 4 #include <string> 5 #include <set> 6 #include <iostream> 7 #include <memory.h> 8 9 typedef unsigned char uint8; 10 normalize(const std::string & line)11std::string normalize(const std::string& line) 12 { 13 static const char tbl[][3] = { "66", "67", "F2", "F3" }; 14 size_t tblNum = sizeof(tbl) / sizeof(tbl[0]); 15 typedef std::set<std::string> StringSet; 16 StringSet suf; 17 18 size_t pos = 0; 19 for (; pos < line.size(); pos += 2) { 20 bool found = false; 21 for (size_t i = 0; i < tblNum; i++) { 22 if (::memcmp(&line[pos], tbl[i], 2) == 0) { 23 found = true; 24 suf.insert(tbl[i]); 25 break; 26 } 27 } 28 if (!found) break; 29 } 30 std::string ret; 31 for (StringSet::const_iterator i = suf.begin(), e = suf.end(); i != e; ++i) { 32 ret += *i; 33 } 34 ret += &line[pos]; 35 return ret; 36 } 37 main()38int main() 39 { 40 std::string line; 41 while (std::getline(std::cin, line)) { 42 std::string normalizedLine = normalize(line); 43 std::cout << normalizedLine << '\n';//std::endl; 44 } 45 } 46