文章

13

粉丝

64

获赞

0

访问

1.6k

头像
充分利用容器特性
P1448 北京理工大学机试题
发布于2024年3月27日 15:19
阅读数 106

#include <iostream>
#include <map>
#include <vector>
#include <set>
using namespace std;
int main()
{
    int m;
    cin >> m;
    while (m--)
    {
        int n, t;
        cin >> n;
        map<int, vector<int>> mp;
        set<int> key;
        int a[n];
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            key.insert(a[i]);
        }
        for (int i = 0; i < n; i++)
        {
            cin >> t;
            mp[t].push_back(a[i]);
        }
        for (auto it : mp)
        {
            map<int, int> count;
            cout << it.first << "={";
            for (auto i : it.second)
                count[i]++;
            for (auto i = key.begin(); i != key.end(); i++)
            {
                if (i != key.begin())
                    cout << "," << *i << "=" << count[*i];
                el...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发