现在的位置: 首页 > 综合 > 正文

NYOJ991 Registration system 【set的用法】

2016年10月04日 ⁄ 综合 ⁄ 共 465字 ⁄ 字号 评论关闭

原题链接

#include <set>
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

char buf[100];
char *digitToString(int n){
	sprintf(buf, "%d", n);
	return buf;
}

int main(){
	int n;
	string str, temp;
	set<string> st;
	cin >> n;
	while(n--){
		cin >> str;
		if(st.count(str) == 0){
			st.insert(str);
			cout << "OK" << endl;
		}
		else{			
			for(int i = 1; ; ++i){
				temp = str;
				if(st.count(temp.append(digitToString(i))) == 0){
					st.insert(temp);
					cout << temp << endl;
					break;
				}
			}
		}
	}
	return 0;
}

801811 长木 Registration system Accepted 0 308 C/C++ 04-08 09:19:26

抱歉!评论已关闭.