Baidu Star 2016 qualifying game D, water problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.