题目链接:http://codeforces.com/problemset/problem/4/C

题意:

如果这个词第一次出现,输出ok

否则输出这个词,并且输出在此之前这个词出现了多少次

解法:

直接双Hash

//UVALive 6959

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int gethash1(char *key){
    LL N = 1998585857;
    LL h = 0;
    while(*key) h = (h*127+(*key++)+N)%N;
    return h%N;
}
int gethash2(char *key){
    LL N = 127398127;
    LL h = 0;
    while(*key) h = (h*127+(*key++)+N)%N;
    return h%N;
}
char s[40];
map<pair<int, int>, int>mp;
int n;
int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%s", s);
        pair<int, int>a;
        a.first=gethash1(s);
        a.second=gethash2(s);
        mp[a]++;
        if(mp[a]==1) printf("OK\n");
        else printf("%s%d\n", s, mp[a]-1);
    }
    return 0;
}