【CODEFORCE 4C】map容器的妙用——Registration system

题目来源:CODEFORCE 4C点击打开链接

本来想用char 模拟的,结果发现太麻烦放弃了。然后想用queue做,发现依然太麻烦,TLE了。

最后想到了MAP,这个传说中的多项映照容器,更奇葩的是,他已经重载了[ ]运算符,访问一个当成下标可以直接切换到另外一个,如果找不到他会自动添加上一个。

最后只花了不到二十行解决了问题,STL果然是个IMBA的东西 = =

#include <iostream>
#include <string>
#include <map>
using namespace std;


int main()
{
	int testcase;
	string temp;
	while(cin>>testcase)
	{
		map<string,int> traget;
		int pointerstr=0;
		for(int i=0;i<testcase;i++)
		{
			cin>>temp;
			pointerstr=traget[temp]++;
			
			if(pointerstr==0)
			{
				cout<<"OK"<<endl;
			}
			else
			{
				cout<<temp<<pointerstr<<endl;
			}
		}
		
			
	}


	return 0;			
}	
	
	



你可能感兴趣的:(【CODEFORCE 4C】map容器的妙用——Registration system)