Epicure先生正在编撰一本美食百科全书。为此,他已从众多的同好者那里搜集到了一份冗长的美食提名清单。既然源自多人之手,其中天然不乏重复的提名,故必须予以筛除。Epicure先生所以登门求助,并认定此事对你而言不过是“一碟小菜”,相信你不会错过在美食界扬名立万的这一良机html
第1行为1个整数n,表示提名清单的长度。如下n行各为一项提名app
全部出现重复的提名(屡次重复的仅输出一次),且以其在原清单中首次出现重复(即第二次出现)的位置为序spa
Inputcode
10 brioche camembert cappelletti savarin cheddar cappelletti tortellni croissant brioche mapotoufu
Outputhtm
cappelletti brioche
1 < n < 6 * 10^5get
All nominations are only in lowercase. No other character is included. Length of each item is not greater than 40.string
Time: 2 secit
Memory: 256 MBio
https://dsa.cs.tsinghua.edu.cn/oj/problem.shtml?id=1150
class
散列表,瞎搞搞
#include<stdio.h> #include<string.h> typedef struct Hash { Hash *next; char str[45]; }Hash; Hash *s[600005]; char str[55]; int Sech(int x) { int sum = 0; Hash *p = s[x]; while(p->next!=NULL) { p = p->next; if(strcmp(p->str+1, str+1)==0) sum++; if(sum==2) return sum; } Hash *temp = new Hash; temp->next = NULL; strcpy(temp->str+1, str+1); p->next = temp; return sum; } int main(void) { int n, i, j, x, y; scanf("%d", &n); for(i=0;i<=600000;i++) { s[i] = new Hash; s[i]->next = NULL; } for(i=1;i<=n;i++) { scanf("%s", str+1); x = y = 0; for(j=1;str[j]!='\0';j++) { x += (str[j]-'a'+1)*j; x %= 1003; } for(j--;j>=1;j--) { y += (str[j]-'a'+j)*j; y %= 597; } y = y*1000+x; x = Sech(y); if(x==1) puts(str+1); } return 0; }