PAT (Advanced Level) Practice A1124 Raffle for Weibo Followers (20 分) (map)

版权声明:假装有个原创声明……虽然少许博文不属于完全原创,但也是自己辛辛苦苦总结的,转载请注明出处,感谢! https://blog.csdn.net/m0_37454852/article/details/88538045

原题链接

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;

typedef long long int LL;
const int MAX = 1010, INF = 1<<30;

int M, N, S;
string name[MAX];
map<string, bool> flag;//注意不能用map<char*, bool> 

int main()
{
    scanf("%d %d %d", &M, &N, &S);
    for(int i=1; i<=M; i++)
    {
        cin>>name[i];
        flag[name[i]] = 0;
    }
    if(M < S) cout<<"Keep going..."<<endl;
    for(int j=S; j<=M; j+=N)
    {
        while(j<=M && flag[name[j]]) j++;//已经中过奖了,便考虑下一个
        if(j > M) break;
        cout<<name[j]<<endl;
        flag[name[j]] = 1;//置为已经中奖
    }
	return 0;
}



猜你喜欢

转载自blog.csdn.net/m0_37454852/article/details/88538045