阿里笔试:去重和排序,重新输出Markdown格式

    xiaoxiao2021-03-25  110

    #include <iostream> #include <algorithm> #include <vector> #include <string> #include <map> using namespace std; int main() { string str; map<int, int> j_1_mp, j_2_mp, content; while (cin >> str) { if (str[0] == '#'&&str[1] != '#') { string numstr; for (int i = 1; i < str.length(); ++i) numstr[i - 1] = str[i]; if (j_1_mp.find(atoi(numstr.c_str())) == j_1_mp.end()) { j_1_mp[atoi(numstr.c_str())]++; cout << str << endl; } else continue; } else if (str[0] == '#'&&str[1] == '#'){ string numstr; for (int i = 2; i < str.length(); ++i) numstr[i - 2] = str[i]; if (j_2_mp.find(atoi(numstr.c_str())) == j_2_mp.end()){ j_2_mp[atoi(numstr.c_str())]++; cout << str << endl; } else continue; } else{ string numstr; for (int i = 1; i < str.length(); ++i) numstr[i - 1] = str[i]; if (content.find(atoi(numstr.c_str())) == content.end()) { content[atoi(numstr.c_str())]++; cout << str << endl; } else continue; } } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-9748.html

    最新回复(0)