https://pintia.cn/problem-sets/994805260223102976/problems/994805265159798784c++
小明 PAT 考了滿分,高興之餘決定發起微博轉發抽獎活動,從轉發的網友中按順序每隔 N 我的就發出一個紅包。請你編寫程序幫助他肯定中獎名單。spa
輸入第一行給出三個正整數 M(≤ 1000)、N 和 S,分別是轉發的總量、小明決定的中獎間隔、以及第一位中獎者的序號(編號從 1 開始)。隨後 M 行,順序給出轉發微博的網友的暱稱(不超過 20 個字符、不包含空格回車的非空字符串)。code
按照輸入的順序輸出中獎名單,每一個暱稱佔一行。若是沒有人中獎,則輸出 Keep going...
。blog
9 3 2 Imgonnawin! PickMe PickMeMeMeee LookHere Imgonnawin! TryAgainAgain TryAgainAgain Imgonnawin! TryAgainAgain
PickMe Imgonnawin! TryAgainAgain
2 3 5 Imgonnawin! PickMe
代碼:Keep going...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; char name[maxn][30]; int m, n, s; map<string, int> mp; int main() { scanf("%d%d%d", &m, &n, &s); for(int i = 1; i <= m; i ++) { scanf("%s", name[i]); } int flag = 0; for(int i = s; i <= m; i = i + n) { while(mp[name[i]]) i ++; if(i > m) break; mp[name[i]] = 1; printf("%s\n", name[i]); flag = 1; } if(flag == 0) { printf("Keep going...\n"); } return 0; }