社区讨论
map写法太简单了
P5266【深基17.例6】学籍管理参与者 5已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @lqhs8p3x
- 此快照首次捕获于
- 2023/12/23 16:12 2 年前
- 此快照最后确认于
- 2023/12/23 16:20 2 年前
CPP
#include <bits/stdc++.h>
using namespace std;
int n;
map<string,int> M;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
int sys;
cin>>sys;
if(sys==1){
string s;
int score;
cin>>s>>score;
M[s]=score;
cout<<"OK"<<endl;
}
if(sys==2){
string s;
cin>>s;
if(M.count(s)){
cout<<M[s]<<endl;
}
else{
cout<<"Not found"<<endl;
}
}
if(sys==3){
string s;
cin>>s;
if(M.count(s)){
M.erase(s);
cout<<"Deleted successfully"<<endl;
}
else{
cout<<"Not found"<<endl;
}
}
if(sys==4){
cout<<M.size()<<endl;
}
}
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...