HDU 2072 Word Count

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=2072

The number of words this problem feel with C write very troublesome, write in C + + is relatively simple. Not much to say, direct sticker code.

#include <iostream>#include<string>#include<vector>#include<sstream>using namespacestd;intmain () {vector<string>s; strings0,s1; intFlag;  while(Getline (CIN,S0)) {if(s0=="#")             Break; Else{s.clear ();            Istringstream sin (s0);  while(sin>>S1) {Flag=0;  for(intI=0; I<s.size (); i++)                {                    if(s[i]==S1) {Flag=1;  Break; }                }                if(flag==0) S.push_back (S1); } cout<<s.size () <<Endl; }    }    return 0;}

Feel the use of set is simpler, this is the online code:

#include <iostream>#include<Set>#include<string>#include<sstream>//don't forget it. using namespacestd; intMain () {stringArt;  while(Getline (cin,art) && Art! ="#") {Istringstream stream (art); stringWord; Set<string>map;  while(Stream >>word)            {Map.insert (word); } cout<<map.size () <<Endl; }        return 0; }  

HDU 2072 Word Count

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.