zoukankan      html  css  js  c++  java
  • registration system(map+思维)

         题意:每次给出一个只含小写字母的字符串,如果之前没出现过,就输出YES,插入到数据库,否则输出  它+数字   的形式,数字按出现顺序排列。

         解析:比如只输入a,会陆续出现a,a1,a2,a3......a10,a11。可以看出来,我们压根不需要每次判断当前字符串的上次出现是什么样子,其实本质上就是原字符串+出现次数的形式而已。所以用map记录次数,每次都++记录下就可以了。

    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    #include<string.h>
    #include<vector>
    #include<cmath>
    #include<string>
    #include<map>
    #include<queue>
    using namespace std;
    typedef long long ll;
    const int maxn = 1e5+10;
    string s;
    int a[maxn];
    int main()
    {
        int n;
        cin>>n;
        map<string,int>mp;
        for(int i=1;i<=n;i++)
        {
            cin>>s;
            if(mp[s]==0)
            {
                cout<<"OK"<<endl;
                mp[s]++;
            }
            else
            {
                cout<<s<<mp[s]<<endl;
                mp[s]++;
            }
        }
    }
  • 相关阅读:
    Python之MySQLdb
    Python 小方法
    Python文件打包
    禅道使用教程
    Linux命令
    安卓自动化测试monkey
    深入分析Java中的中文编码问题
    Linux命令搜索
    文件上传的类型选择控制
    MySql格式化日期函数
  • 原文地址:https://www.cnblogs.com/liyexin/p/12757311.html
Copyright © 2011-2022 走看看