Hi I'm using a Trie implementation to solve this problem, but oin the codeforces' servers I'm getting runtime error, and on my pc and on Ideone is normal. Any Ideas ? http://codeforces.com/contest/4/problem/C https://ideone.com/dvRL3b
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define MAXN ('z'-'a'+2)
#define VALUE(c) ( (c)-'a' )
struct Trie
{
Trie *m[MAXN];
int count;
}trie;
int insert(Trie * t, char * w){
if(w[0]=='\0'){
t->count++;
return t->count;
}
if(t->m[VALUE(w[0])] == NULL){
t->m[VALUE(w[0])] =(Trie *) malloc(sizeof(Trie));
}
return insert(t->m[VALUE(w[0])] , w+1);
}
int main(){
int t;
scanf("%d",&t);
for (int i = 0; i < t; ++i)
{
char *w = NULL;
w = (char *)malloc(sizeof(char));
scanf("%s",w);
//printf("%s\n", w);
int resp = insert(&trie,w);
if(resp > 1){
printf("%s%d\n", w,resp-1);
}else{
printf("OK\n");
}
}
return 0;
}