AcWing 3576. 分组统计
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e2 + 10;
const int M = 1e3 + 10;
int t, n, m, k, l, r, op, x, y;
int f[N];
int g[N][M];
set<int> st;
void solve() {
cin>>t;
while (t--) {
cin>>n;
st.clear();
k = 0;
for (int i = 1; i <= n; i++) {
cin >> f[i];
st.insert(f[i]);
memset(g[i], 0, sizeof(g[i]));
}
for (int i = 1; i <= n; i++) {
cin >> x;
k = max(k, x);
g[x][f[i]]++;
}
for (int i = 1; i <= k; i++) {
cout << i << "=";
cout << "{";
for (int num : st) {
cout << num << "=" << g[i][num];
if (*st.rbegin() != num)cout << ",";
}
cout << "}";
cout << "\n";
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}