set + 二维数组 题解 | #分组统计#
分组统计
https://www.nowcoder.com/practice/5cb47b86911c4aa48722e531a51ec823
#include <iostream> #include <set> #include <cstring> using namespace std; int f[110][1010]; //i组j数 int a[1010], b[1010]; int main(){ int m, n; cin>>m; while(m--){ memset(f, 0, sizeof f); set<int> s, q; cin>>n; for(int i = 0; i < n; i ++){ cin>>a[i]; s.insert(a[i]); } for(int j = 0; j < n; j ++){ cin>>b[j]; q.insert(b[j]); } for(int i = 0; i < n; i ++) f[b[i]][a[i]] ++; for(auto t : q){ cout<<t<<"={"; for(auto p : s){ if(p != *s.rbegin()) cout<<p<<"="<<f[t][p]<<","; else cout<<p<<"="<<f[t][p]; } cout<<"}"<<endl; } } return 0; }