A very simple question, the main is to use a string hash, the string is processed into integers. Then you can continue with the hash, or you can use a map like me to get it done.
/** Author:ben*/#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<ctime>#include<iostream>#include<algorithm>#include<queue>#include<Set>#include<map>#include<stack>#include<string>#include<vector>#include<deque>#include<list>#include<functional>#include<numeric>#include<cctype>using namespaceStd;typedefLong LongLL;/** Input non-negative integer * supports types such as short, int, long, long long, and so on (modify Typec). * Usage Typec a = Get_int (); return-1 means end of input*/typedefintTypec;typec Get_int () {Typec res=0, ch; while(! (ch = getchar ()) >='0'&& CH <='9')) { if(ch = =EOF)return-1; } Res= CH-'0'; while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ (CH-'0'); returnRes;}//Enter an integer (including a negative integer, so the return value cannot be used to determine whether the input to EOF, the function when input to EOF, return-1), the use of int a = Get_int2 ();intGet_int2 () {intres =0, ch, flag =0; while(! (ch = getchar ()) >='0'&& CH <='9')) { if(ch = ='-') Flag=1; if(ch = =EOF)return-1; } Res= CH-'0'; while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ (CH-'0'); if(Flag = =1) Res= -Res; returnRes;}/** * Enter a string into str, similar to scanf ("%s", str), which ignores whitespace characters in the buffer. The return value is the length of the input string *, and a return of 1 indicates the end of the input. */intGET_STR (Char*str) { CharC; while((c = GetChar ()) <=' ') { if(c = =EOF) { return-1; } } intI =0; while(C >' ') {Str[i+ +] = C; c =GetChar (); } Str[i]=0; returnI;}intHash_code (Const Charstr[]) { inth =0; for(inti =0; Str[i] >0; i++) {h= to* H +Str[i]; } returnh;}intMain () {intN =Get_int (); Charstr[ -]; Map<int,int>Mymap; for(inti =0; i < N; i++) {get_str (str); intLen =strlen (str); Sort (str, str+Len); inthash =Hash_code (str); if(Mymap.count (hash) >0) {printf ("%d\n", mymap[hash]++); } Else{printf ("0\n"); Mymap[hash]=1; } } return 0;}
Baidu Star 2016 qualifying game D, water problem