forked from keshavnandan/Topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsername_sol.cpp
58 lines (52 loc) · 1.19 KB
/
Username_sol.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
template <typename T>
string NumberToString ( T Number )
{
ostringstream ss;
ss << Number;
return ss.str();
}
class UserName {
public:
string newMember(vector <string>, string);
};
string UserName::newMember(vector <string> existingNames, string newName) {
set<string> st(existingNames.begin(), existingNames.end());
char s[1024];
int num = 0;
while(1){
if(num == 0)
sprintf(s, "%s", newName.c_str());
else
sprintf(s, "%s%d", newName.c_str(), num);
if(st.find(string(s)) == st.end()) break;
num++;
}
return string(s);
}
int main(){
string s = "TygerTyger";
string sa[] = {"MasterOfDisaster", "TygerTyger1", "DingBat", "Orpheus",
"TygerTyger", "WolfMan", "MrKnowItAll"};
vector<string> vs(sa, sa+7);
cout<<UserName().newMember(vs,s)<<endl;
}