STL入门2

1:给出n个字符串,输出每个字符串是第几个出现的字符串?多组数据

2:对每组数据,第一行输入n表示接下来有n个字符串 1 <= n <= 100000接下来的n行,每行输入一个非空的且长度最多为10的仅由大写字母组成的字符串

3:输出共n行,对每一行的字符串,输出其是第几个出现的字符串。

解题思路:直接map//mp.clear();

#include<iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std;
int main ()
{
    int n;
    map <string ,int>m;
    char ss[1005];
    while(~scanf("%d",&n))
    {
        m.clear();
        int flag=1;
        while(n--)
        {
            scanf("%s",ss);
            if(!m.count(ss))
                m[ss]=flag++;
            printf("%d
",m[ss]);
        }  
    }
    return 0;
}


想的太多,做的太少。
原文地址:https://www.cnblogs.com/pealicx/p/6115663.html