#include <iostream> struct Participant { int id; bool canParticipate; int previousFinals; }; int main() { int n; std::cin >> n; Participant *participants = new Participant[n]; for (int i = 0; i < n; ++i) { std::string s; int x; std::cin >> s >> x; participants[i] = {i + 1, s == "TAK", x}; } int validCount = 0; for (int i = 0; i < n; ++i) { if (participants[i].canParticipate) { participants[validCount++] = participants[i]; } } int *finalists = new int[20]; int *top10 = new int[10]; int *next10 = new int[10]; int top10Count = 0, next10Count = 0, finalistsCount = 0; for (int i = 0; i < validCount; ++i) { if (top10Count < 10) top10[top10Count++] = participants[i].id; else if (participants[i].previousFinals < 2 && next10Count < 10) next10[next10Count++] = participants[i].id; } for (int i = 0; i < top10Count; ++i) finalists[finalistsCount++] = top10[i]; for (int i = 0; i < next10Count; ++i) finalists[finalistsCount++] = next10[i]; while (finalistsCount < 20) { for (int i = 0; i < validCount; ++i) { bool found = false; for (int j = 0; j < finalistsCount; ++j) { if (finalists[j] == participants[i].id) { found = true; break; } } if (!found) { finalists[finalistsCount++] = participants[i].id; if (finalistsCount == 20) break; } } } for (int i = 0; i < finalistsCount - 1; ++i) { for (int j = i + 1; j < finalistsCount; ++j) { if (finalists[i] > finalists[j]) { int temp = finalists[i]; finalists[i] = finalists[j]; finalists[j] = temp; } } } for (int i = 0; i < finalistsCount; ++i) std::cout << finalists[i] << " "; std::cout << std::endl; delete[] participants; delete[] finalists; delete[] top10; delete[] next10; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | #include <iostream> struct Participant { int id; bool canParticipate; int previousFinals; }; int main() { int n; std::cin >> n; Participant *participants = new Participant[n]; for (int i = 0; i < n; ++i) { std::string s; int x; std::cin >> s >> x; participants[i] = {i + 1, s == "TAK", x}; } int validCount = 0; for (int i = 0; i < n; ++i) { if (participants[i].canParticipate) { participants[validCount++] = participants[i]; } } int *finalists = new int[20]; int *top10 = new int[10]; int *next10 = new int[10]; int top10Count = 0, next10Count = 0, finalistsCount = 0; for (int i = 0; i < validCount; ++i) { if (top10Count < 10) top10[top10Count++] = participants[i].id; else if (participants[i].previousFinals < 2 && next10Count < 10) next10[next10Count++] = participants[i].id; } for (int i = 0; i < top10Count; ++i) finalists[finalistsCount++] = top10[i]; for (int i = 0; i < next10Count; ++i) finalists[finalistsCount++] = next10[i]; while (finalistsCount < 20) { for (int i = 0; i < validCount; ++i) { bool found = false; for (int j = 0; j < finalistsCount; ++j) { if (finalists[j] == participants[i].id) { found = true; break; } } if (!found) { finalists[finalistsCount++] = participants[i].id; if (finalistsCount == 20) break; } } } for (int i = 0; i < finalistsCount - 1; ++i) { for (int j = i + 1; j < finalistsCount; ++j) { if (finalists[i] > finalists[j]) { int temp = finalists[i]; finalists[i] = finalists[j]; finalists[j] = temp; } } } for (int i = 0; i < finalistsCount; ++i) std::cout << finalists[i] << " "; std::cout << std::endl; delete[] participants; delete[] finalists; delete[] top10; delete[] next10; return 0; } |