zoukankan      html  css  js  c++  java
  • CodeForces-4C Registration system

    // Registration system.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
    //
    
    
    #include <iostream>
    #include <map>
    #include <string>
    using namespace std;
    int main()
    {
        //int n,index=0,ds=1;
        int n;
        cin >> n;
        //string* s = new string[n];
        //for (int i = 0;i < n;i++) {
            //scanf("%f", s[i]);
        //}
        string s;
        //map<int, string> m;
        map<string, unsigned int> m;
        //for (int i = 0;i < n;i++) {
           //scanf_s("%s
    ", s);
             //cin >> s;
           //m.insert(pair<int,string>(i,s));
           //m.insert(pair<string, int>(s, i));
        //}
        //map<int,string>::iterator iter;
        //map<string, int>::iterator iter;
        //iter = m.begin();
        while (n--) {
            cin >> s;
            //scanf_s("%c
    ", &s);
            if (m.find(s)==m.end()) {
                printf_s("%s
    ", "OK");
                m[s] = 0;
            }
            else {
                m[s]++;
                //printf_s("%s,%d
    ",s,m[s]);
                std::cout <<s<<m[s]<<endl;
            }
            m.insert(pair<string, unsigned int>(s, m[s]));
            //index++;
        }
        //std::cout << "Hello World!
    "; 
    }
    
    // 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
    // 调试程序: F5 或调试 >“开始调试”菜单
    
    // 入门提示: 
    //   1. 使用解决方案资源管理器窗口添加/管理文件
    //   2. 使用团队资源管理器窗口连接到源代码管理
    //   3. 使用输出窗口查看生成输出和其他消息
    //   4. 使用错误列表窗口查看错误
    //   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
    //   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件

    #include "pch.h"
    #include <iostream>
    #include <algorithm>
    #include <vector>
    //#include <map>
    #include <string>
    using namespace std;
    const int N = 1e5 + 9;
    pair<int,int> ans[N];
    vector<pair<string, int>> vp;
    //map<string, int> mp;
    //map<pair<string, int>> mp;
    int main() {
        int n;string s;
        cin >> n;
        for (int i = 0;i < n;i++) {
            cin >> s;
            vp.push_back(pair<string, int>(s,i));
            //vp.push_back(make_pair<string, int>(s, i));
            //mp.insert(pair<string, int>(s, i));
            //sort(vp.begin(),vp.end());
        }
            //sort(mp.begin(), mp.end());
              sort(vp.begin(), vp.end());
            //vector<pair<string,int>>::iterator iter = vp.begin();    
             
            //pair<string, int> prev;
            //map<string, int>::iterator iter;
            //string prev = mp.begin()->first;
              string prev = vp[0].first;
            //string prev = mp[0].first;
              //printf("%s
    ", "OK");
              int count = 0;
              ans[vp[0].second] = make_pair(0, count);
              for (int i = 1;i < n;i++) {
                //iter++;
                //if (prev == iter->first) {
                  if (prev == vp[i].first) {
                      count++;
                      //ans[vp[i].second].second = make_pair(i,count);          
                  }
                  else {
                      count = 0;
                      prev = vp[i].first;
                      //ans[vp[i].second] = make_pair(i, count);
                  }
                //}
                  ans[vp[i].second] = make_pair(i, count);
              }
              for (int i = 0;i < n;i++) {
                  if (ans[i].second == 0) {
                      printf("%s
    ", "OK");
                  }
                  else {
                  std::cout << vp[ans[i].first].first << ans[i].second << endl;
                  }
              }
            return 0;
        }

  • 相关阅读:
    apache phoenix查询缓慢问题
    hbase replication原理分析
    ServerSocketChannel实现多Selector高并发server
    hbase hmaster故障分析及解决方案:Timedout 300000ms waiting for namespace table to be assigned
    mapreduce出现类似死锁情况
    【转】How-to: Enable User Authentication and Authorization in Apache HBase
    最近的一些杂念思考
    我究竟该成为什么样的一个人
    解决linux下 使用netcore生成图片报错的问题:The type initializer for 'Gdip' threw an exception
    linux 编译安装nginx
  • 原文地址:https://www.cnblogs.com/ZHONGZHENHUA/p/10766100.html
Copyright © 2011-2022 走看看