1 条题解
-
0
#include <iostream> #include <vector> #include <string> using namespace std; int main() { int players, squares, cards; while (cin >> players && players != 0) { cin >> squares >> cards; string board; cin >> board; vector<string> deck(cards); for (int i = 0; i < cards; ++i) { cin >> deck[i]; } vector<int> pos(players, -1); // 起点在 -1 int winner = -1, total_drawn = 0; for (int i = 0; i < cards && winner == -1; ++i) { string card = deck[i]; int player = i % players; int current_pos = pos[player]; // 查找下一个位置 int count = 0; for (int j = current_pos + 1; j < squares; ++j) { if (board[j] == card[0]) { ++count; if (count == card.size()) { pos[player] = j; break; } } } if (count < card.size()) { pos[player] = squares - 1; // 跳到最后 } ++total_drawn; if (pos[player] == squares - 1) { winner = player; break; } } if (winner != -1) { cout << "Player " << (winner + 1) << " won after " << total_drawn << " cards." << endl; } else { cout << "No player won after " << cards << " cards." << endl; } } return 0; }
- 1
信息
- ID
- 577
- 时间
- 1000ms
- 内存
- 10MiB
- 难度
- 8
- 标签
- 递交数
- 2
- 已通过
- 1
- 上传者