CF855A Tom Riddle's Diary

洛谷题面

题目大意

给定 \(n\) 个字符串,每一次在线回答该字符串在之前出现过几次。

题目分析

可以字符串 \(\rm Hash\),但是我不会,于是考虑 \(\rm STL\)\(\verb!map!\)

定义一个 map<string,int>,第一个位置记录字符串,另一个记录出现次数。输入一个字符串后,将第二个位置加一即可。

代码

//2021/11/18

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <cstdio>

#include <climits>//need "INT_MAX","INT_MIN"

#include <map>

#include <string>

#define enter() putchar(10)

#define debug(c,que) cerr<<#c<<" = "<<c<<que

#define cek(c) puts(c)

#define blow(arr,st,ed,w) for(register int i=(st);i<=(ed);i++)cout<<arr[i]<<w;

#define speed_up() std::ios::sync_with_stdio(false)

#define endl "\n"

namespace Newstd
{
	inline int read()
	{
		char c;
		bool flag=false;
		while((c=getchar())<'0' || c>'9')
		{
		    if(c=='-') flag=true;
		}
		int res=c-'0';
		while((c=getchar())>='0' && c<='9')
		{
		    res=(res<<3)+(res<<1)+c-'0';
		}
		return flag?-res:res;
	}
	inline void print(int x)
	{
		if(x<0)
		{
			putchar('-');x=-x;
		}
		if(x>9)
		{
			print(x/10);
		}
		putchar(x%10+'0');
	}
}

using namespace Newstd;

using namespace std;

int n;

map<string,bool>mp;

int main(void)
{
	n=read();
	
	for(register int i=1;i<=n;i++)
	{
		string now;
		
		cin>>now;
		
		if(mp[now]==false)
		{
			mp[now]=true;
			
			puts("NO");
		}
		
		else
		{
			puts("YES");
		}
	}
	
	return 0;
}
posted @ 2021-11-22 23:05  Coros_Trusds  阅读(94)  评论(0)    收藏  举报