C - Registration system

C - Registration system
Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.

Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1,name2, ...), among these numbers the least i is found so that namei does not yet exist in the database.

Input

The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.

Output

Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.

Sample Input

Input
4
abacaba
acaba
abacaba
acab
Output
OK
OK
abacaba1
OK
Input
6
first
first
second
second
third
third
Output
OK
first1
OK
second1
OK
third1
#include<iostream>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <vector>
#include <bitset>
#include <cstdio>
#include <string>
#include <numeric>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
#define Exp 1e-8
#define inf 0x7fffffff
#define Read freopen("in.txt","r",stdin)
#define Write freopen("out.txt","w",stdout)
#define maxn 55
#define mod 1000000007

map<string ,int>m;//map秒过= =!

void read()
{
    int n;
    cin>>n;
    for(int f=0; f<n; f++)
    {
        string a;
        cin>>a;
        m[a]++;
        if(m[a]==1)
            cout<<"OK"<<endl;
        else
            cout<<a<<m[a]-1<<endl;
    }
}

int main()
{
    read();
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
学生选课系统是一个常见的应用程序,用于管理学生的选课信息。在C语言中,可以使用文件操作和算法来实现学生选课系统的功能。 以下是一个简单的C语言学生选课系统的示例: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> // 定义课程结构体 typedef struct { char courseCode[10]; char courseName[50]; char courseProperty[20]; char semester[20]; int credit; } Course; // 定义学生结构体 typedef struct { char studentID[10]; char studentName[50]; Course courses[10]; int numCourses; } Student; // 函数声明 void displayMenu(); void searchCourse(Student* student); void displayCourseInfo(Student* student); void addCourse(Student* student); void removeCourse(Student* student); int main() { Student student; student.numCourses = 0; int choice; do { displayMenu(); printf("Enter your choice: "); scanf("%d", &choice); switch (choice) { case 1: searchCourse(&student); break; case 2: displayCourseInfo(&student); break; case 3: addCourse(&student); break; case 4: removeCourse(&student); break; case 5: printf("Exiting the program...\n"); break; default: printf("Invalid choice. Please try again.\n"); break; } } while (choice != 5); return 0; } // 显示菜单 void displayMenu() { printf("-- Student Course Registration System ---\n"); printf("1. Search course\n"); printf("2. Display course information\n"); printf("3. Add course\n"); printf("4. Remove course\n"); printf("5. Exit\n"); } // 搜索课程 void searchCourse(Student* student) { // 根据菜单选择查询字段,实现相应的查找算法 // 这里只是一个示例,具体的实现需要根据需求进行编写 printf("Searching course...\n"); } // 显示课程信息 void displayCourseInfo(Student* student) { // 分屏显示课程信息,每屏10条课程记录,按任意键继续 // 这里只是一个示例,具体的实现需要根据需求进行编写 printf("Displaying course information...\n"); } // 添加课程 void addCourse(Student* student) { // 添加课程到学生的选课列表中 // 这里只是一个示例,具体的实现需要根据需求进行编写 printf("Adding course...\n"); } // 移除课程 void removeCourse(Student* student) { // 从学生的选课列表中移除课程 // 这里只是一个示例,具体的实现需要根据需求进行编写 printf("Removing course...\n"); } ``` 这个示例中,我们使用了结构体来定义课程和学生的信息。通过菜单选择,可以进行课程的搜索、课程信息的显示、课程的添加和课程的移除等操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值