Word Count (STL set)

Source: Internet
Author: User

Word Count problem descriptionlily's good friend xiaoou333 has been blank recently. He thought of something meaningless, that is, counting the total number of different words in an article. The following task helps xiaoou333 solve this problem. Input contains multiple groups of data, one row in each group, and each group is a small article. Each small article is composed of lower-case letters and spaces with no punctuation marks. If it encounters "#", the input ends. Each group outputs only one integer, which is a separate line. This integer represents the total number of different words in an article. Sample Input
 
You are my friend #
Sample output
 4  set usage and features:     1. Elements in the set are arranged from small to large and there are no repeated elements like the set;   2, set 
    
     :: iterator S. begin () s. end () 
     
 # include 
    
      # include 
     
       # include 
      
        # include 
       
         # include 
        
          # include 
         
           using namespace STD; string Wen, STR; set 
          
            dict; int main () {While (Getline (CIN, Wen) & Wen! = "#") {Stringstream CH (Wen); // find a single word in the text string while (CH> Str) dict. insert (STR); printf ("% d \ n", dict. size (); dict. clear () ;}return 0 ;}
          
         
        
       
      
     
    

Similar to map:
# Include <iostream> # include <cstdio> # include <string> # include <map> # include <cstring> # include <sstream> using namespace STD; Map <string, int> m; string STR, ch;/* int main () {While (Getline (CIN, STR) & Str! = "#") {Int Len = Str. size (); int I = 0; M. clear (); While (I <Len) {CH = ""; while (I <Len & 'A' <= STR [I] & STR [I] <= 'Z') CH + = STR [I ++]; if (Ch! = "") {M [CH] = 1;} I ++;} printf ("% d \ n", M. size ();} return 0;} */INT main () {While (Getline (CIN, STR) & Str! = "#") {Stringstream SS (STR); M. clear (); While (SS> CH) {M [CH] = 1;} printf ("% d \ n", M. size () ;}return 0 ;}


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.