int main(){
int n;
cin>>n;
char *str[40];
str=new char [10000][40]; //I don't know how to initialize this array
std::map<char*,int> system;
int i,j;
//solving Question 4C @ Codeforces
for(i=0;i<n;i++){
cin>>str[i];
}
for(i=0;i<n;i++){
int count=0;
for(std::map<char*,int>::iterator iter=system.begin();iter!=system.end();iter++){
if(strcmp(iter->first,str[i])==0){
count=++iter->second;
}
else if(strcmp(str[i],iter->first)>0){
break;
}
}
if(count==0){
system[str[i]]=1;
cout<<"OK"<<endl;
}
else{
char *strint;
strint=new char[5];
strint=convert(count);
strcat(str[i],strint);
cout<<str[i]<<endl;
}
}
}
Question: http://codeforces.com/problemset/problem/4/C
I am looking for a way that I could put the char array as an element of the map to help solving the scenario, however, I ended up with either screwing up the map.insert function when I declare str[n][40] as str, system as , (Could somebody please explain why map.insert(str[i],1) won't work in this case? It would be sweet to clarify the concepts) or in this case, fails to initialize the char*str[40] array.
I wonder what is the legit way to do this?
std::stringthen ;-) ? You code currently leaks like a colander.std::vector<std::string>v(40)?std::mapis usually not what you want to do. Why don't you usestd::vectorandstd::string? There's no need to program like it's 1969 any more.