题目:

AC代码:
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <string>
using namespace std;
map <string,vector<string>> a;
int n;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
int opt;
cin>>opt;
if(!opt)
{
string p,x;
cin>>p>>x;
a[p].push_back(x);
}
else
{
string p;
cin>>p;
a[p].clear();
}
}
for(auto to:a)
{
if(to.second.empty()) continue;
else
{
cout<<to.first<<" ";
for(auto t:to.second) cout<<t<<" ";
cout<<endl;
}
}
return 0;
}
该博客展示了一段C++代码,用于管理字符串到字符串向量的映射。程序读取用户输入的指令,添加或清除映射关系,并打印结果。主要涉及的数据结构包括map和vector。

被折叠的 条评论
为什么被折叠?



