建议降橙
查看原帖
建议降橙
1271613
A_W_Lee楼主2024/10/12 14:09

RT
只是码量看着有点大当我没说,没任何思维难度和坑点。
映射的模板,这么几行就AC了

#include<bits/stdc++.h>
using namespace std;
map<string,int>s;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,op,cnt=0;
	cin>>n;
	while(n--)
	{
		string name;
		int score;
		cin>>op;
		if(op==1)
		{
			cin>>name>>score;
			if(s.find(name)==s.end()) cnt++;
			s[name]=score;
			cout<<"OK"<<'\n';
		}
		if(op==2)
		{
			cin>>name;
			if(s.find(name)==s.end()) cout<<"Not found"<<'\n';
			else cout<<s[name]<<'\n';
		}
		if(op==3)
		{
			cin>>name;
			if(s.find(name)==s.end()) cout<<"Not found"<<'\n';
			else
			{
				cnt--;
				s.erase(name);
				cout<<"Deleted successfully"<<'\n';
			}
		}
		if(op==4)
		{
			cout<<cnt<<'\n';
		}
	}
	
	
	return 0;
}
2024/10/12 14:09
加载中...