直接用set和map做個(gè)偽hash就好了。
注意keep going后面三個(gè)點(diǎn)。。我復(fù)制還復(fù)制少了。。哭暈
#include <iostream>#include <vector>#include <string>#include <set>#include <map>#include <cstring>#define MAX 1010using namespace std;int m, n, i;bool isVis[MAX];string list[MAX];set <string> s;int pos = 0;map <string, int> str2int;int main() { cin >> m >> n >> i; for (int j = 1; j <= m; j++) { cin >> list[j]; s.insert(list[j]); } set <string>::iterator it; for (it = s.begin(); it != s.end(); it++) { str2int[*it] = pos++; } memset(isVis, false, sizeof(isVis)); bool tag = false; for (int j = i; j <= m; ) { if (!isVis[str2int[list[j]]]) { isVis[str2int[list[j]]] = true; tag = true; cout << list[j] << endl; j += n; } else { j++; } } if (!tag) cout << "Keep going..." << endl; return 0;}
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注