Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <cstdio>
#include <iostream>
#include <map>
int main(){
int n; scanf("%d\n", &n);
std::map<std::string,long> database;
std::string name("");
while(n--){
getline(std::cin, name);
if(database.find(name) == database.end()){puts("OK");database[name] = 1;}
else{std::cout << name << database[name] << std::endl; ++database[name];}
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
4
abacaba
acaba
abacaba
acab
abacaba
acaba
abacaba
acab
Output
OK
OK
abacaba1
OK
OK
abacaba1
OK
Demonstration
Codeforces Solution-C. Registration system-Solution in C, C++, Java, Python