HDU 1251 Statistical puzzles

Source: Internet
Author: User

Click here to transfer to HDU 1251

 * * Statistical puzzle **problem  description  ignatius  recently encountered a problem, the teacher gave him a lot of words (only lowercase letters, no duplicate words appear), Now the teacher asked him to count the number of words prefixed by a string (the word itself is also its own prefix). input  the first part of the input data is a list of words, one word per line, and the length of the word does not exceed 10 , They represent the words that the teacher handed to ignatius , and a blank line represents the end of the Word table. The second part is a series of questions, one question per line, and each question is a string. Note: The subject has only one set of test data, processing to the end of the file. output  for each question, give the number of words prefixed with the string. sample  input  bananaband  Beeabsoluteacmbabband  abcsample  Output  2  3  1  Span class= "Hljs-number" >0 

Problem-Solving ideas: I originally wanted to use the trie tree, but I think the code is too long, and I do not quite understand, and so I will when I fill in, and now use the map function in the STL:

Directly on the code bar:

#include <iostream>#include <cstring>#include <cstdio>#include <map>using namespace STD;Charstr[ -];intMain () { Map<string, int>M while(Gets (str)) {intLen =strlen(str);if(!len) Break; for(intI=len; I>0; i--) {Str[i] =' + ';        m[str]++; }    } while(Gets (str)) {printf("%d\n", M[str]); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 1251 Statistical puzzles

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.