Description
给出n个字符串,输出每个字符串是第几个出现的字符串?
不明白题意?看样例吧,,
Input
多组数据
对每组数据,第一行输入n表示接下来有n个字符串 1 <= n <= 100000
接下来的n行,每行输入一个非空的且长度最多为10的仅由大写字母组成的字符串
Output
输出共n行,对每一行的字符串,输出其是第几个出现的字符串。
Sample Input
Raw
6
AB
CD
EF
AB
EF
GG
Sample Output
Raw
1
2
3
1
3
4
解题思路:使用stl函数unordered_map
#include <iostream>
#include <stdio.h>
#include<unordered_map>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n) != EOF)
{
int cnt = 1;
unordered_map<string,int> str;
char s[15];
for(int i = 1; i <= n; i++)
{
scanf("%s",s);
if(str.find(s) == str.end())
str[s] = cnt++;
printf("%d\n",str[s]);
}
}
return 0;
}