目录

蓝桥杯备考unordered_map基础用法题-学籍管理

目录

蓝桥杯备考:unordered_map基础用法题 —学籍管理

https://i-blog.csdnimg.cn/direct/9f09000e40e848688979032411fc5dc5.png

我们用unorderedmap绑定名字和成绩,然后进行n次操作 主要是锻炼我们对map接口的用法的理解

#include <iostream>
#include <unordered_map>
using namespace std;

unordered_map<string,int> mp;


int main()
{
	int n;cin >> n;
	while(n--)
	{
		int op,score;string s;
		cin >> op;
		if(op == 1)
		{
			cin >> s >> score;
			mp[s] = score;
			cout << "OK" << endl;
		}
		else if(op == 2)
		{
			cin >> s;
			if(!mp.count(s))
			{
				cout << "Not found" << endl;
			}
			else
			{
				cout << mp[s] << endl;
			}
		}
		else if(op == 3)
		{
			cin >> s;
			if(mp.count(s))
	     	{	
			mp.erase(s);
			cout << "Deleted successfully" << endl;
	     	}
	     	else
	     	cout << "Not found" << endl;
		}
		else
		{
			cout << mp.size() << endl;
		}
	}
	
	
	
	
	
	
	
	
	
}