直接用set和map做个伪hash就好了。
注意keep going后面三个点。。我复制还复制少了。。哭晕
#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;}
新闻热点
疑难解答