map例题

    科技2024-10-31  18

    题目一:B - Journey Planning 题目解析:https://blog.csdn.net/qq_45712954/article/details/108953921 题目二:CF4C Registration system 题目链接:https://www.luogu.com.cn/problem/CF4C 题解:用户名一对一,所以用map解答,用到了find函数 代码:

    #include<map> #include<iostream> #include<string> #define maxn 101000 using namespace std; map<string,int>m; int con[maxn]={0};//计数 int main() { int n; string s; scanf("%d",&n); map<string,int>::iterator it; for(int i=0;i<n;i++) { cin>>s; it=m.find(s); if(it==m.end())//没找到,不存在 { m[s]=i; cout<<"OK"<<endl; } else { int t=it->second;//it可直接调用 con[t]++;//找到之后的序号 cout<<s<<con[t]<<endl; } } return 0; }
    Processed: 0.023, SQL: 8