按照题意模拟即可。
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 100005;
int n, cnt, ans[N];
bool vis[5][10], b[6][5];
string anss[N];
const string name[] {"", "IGOR", "LEA", "MARINO", "SONJA", "VIKTOR"};
const int nxt[] {0, 2, 3, 4, 5, 1};
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
cin >> n;
int win = 4, now = win, cf;
for (int i = 1, j = 1, x, y; i <= n; ++i, j = 1) {
int Max = -1; bool flag = false; // 是否存在红色
for (char ch; j < 6; ++j, now = nxt[now]) {
cin >> ch >> y;
if (ch == 'Y') x = 3;
else if (ch == 'Z') x = 4;
else if (ch == 'C') x = 1;
else x = 2;
if (vis[x][y] || b[now][x]) { anss[++cnt] = name[now], ans[cnt] = i; continue; }
if (j == 1) cf = x;
vis[x][y] = true, b[now][cf] = (j != 1 && cf != x);
if (x == 1) {
if (!flag || y > Max) Max = y, win = now;
flag = true;
}
if (!flag && x == cf && y > Max) Max = y, win = now; // 第一个打出红牌
}
now = win;
}
cout << cnt << '\n';
for (int i = 1; i <= cnt; ++i) cout << ans[i] << ' ' << anss[i] << '\n'; // 输出
return 0;
}