hdu2072 string problems

Source: Internet
Author: User
Tags set set

Problem descriptionlily's good friend xiaoou333 recently very empty, he thought of a meaningless thing, is to count the number of different words in an article. Your task below is to help xiaoou333 solve the problem. Input has multiple sets of data, each set of rows, each of which is a small article. Each small article is composed of lowercase letters and spaces, no punctuation, and when you encounter #, the input ends. Output each group only outputs an integer, which represents the total number of different words in an article. Sample Inputyou is my friend# sample Output4

Set of sets, for this is not very well understood ...

The set is a collection, so the elements in the collection are not allowed to be duplicated and, if necessary, need to be multiset

Here to StringStream, in the Sstream header file, use see: http://www.cppblog.com/Sandywin/archive/2007/07/13/27984.html,

Example: int and string conversions:

int x=1000;

string result;

Streamstring str;

str<<x;

str>>result;

result is 1000;

StringStream stream ends with a space as the read end identifier

Because it is more than one set of data, the final need to clear the set set, the first time no clear, WA twice

AC Code:

1#include <iostream>2#include <string>3#include <sstream>4#include <Set>5 using namespacestd;6 7 Set<string>s;8 9 intMain ()Ten { One     stringStr,ss; A      while(Getline (CIN,STR) &&str[0]!='#') -     { - s.clear (); theStringStream Stream (str);//Assignment: Stream >> result, each time with a space as the end of the read ID -          while(stream>>ss) - S.insert (ss); -Cout<<s.size () <<Endl;  +     } -     return 0; +}
View Code

hdu2072 string problems

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.