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\n", 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\n", &s); if (m.find(s)==m.end()) { printf_s("%s\n", "OK"); m[s] = 0; } else { m[s]++; //printf_s("%s,%d\n",s,m[s]); std::cout <<s<<m[s]<<endl; } m.insert(pair<string, unsigned int>(s, m[s])); //index++; } //std::cout << "Hello World!\n"; } // 运行程序: 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\n", "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\n", "OK"); } else { std::cout << vp[ans[i].first].first << ans[i].second << endl; } } return 0; }