https://yukicoder.me/problems/no/714
解法
https://yukicoder.me/submissions/272888
頑張って実装する問題であるが、mapを使って実装しよう。
面倒なのが、食べたいものリストがmultisetで与えられる所である。
これをmapを使うことで解決する。
「wishlist[i][s] := 席iに座っている人が寿司sを後何個食べたいか」とする。
データ0が来たら、wishlistを構築する。
wishlist[n][s]++をしていけばいい。
データ1が来たら、iを1から20へ順番にまわして、wishlist[i][b]が正である席を探す
データ2が来たらwishlistを丸々クリアする。
データ構造をmapにしようと決めると、実装に手間取りにくいだろう。
int N; map<string,int> wishlist[21]; //--------------------------------------------------------------------------------------------------- void _main() { cin >> N; rep(_, 0, N) { int type; cin >> type; if (type == 0) { int n, m; cin >> n >> m; rep(i, 0, m) { string s; cin >> s; wishlist[n][s]++; } } else if (type == 1) { string b; cin >> b; int ng = 1; rep(i, 1, 21) if (wishlist[i][b]) { wishlist[i][b]--; printf("%d\n", i); ng = 0; break; } if (ng) printf("-1\n"); } else { int c; cin >> c; wishlist[c].clear(); } } }