HDU 2072 words, set, strtok

Source: Internet
Author: User
Tags strtok

Stl_set operation:

St. Begin ()

Returns the iterator pointing to the first element.

St. End ()

Returns the iterator pointing to the end element.

St. rbegin ()

Returns the reverse iterator pointing to the end of the linked list.

St. rend ()

Returns the iterator pointing to the previous position.

St. Clear ()

Clear iterator

St. Count (key_type key)

Returns the number of elements of a value.

St. Empty ()

Returns true if it is null.

St. Size ()

Number of returned Elements

St. Swap ()

Exchange two set variables

St. insert (VAL)

St. insert (LOC, Val)

St. insert (START, end );

Insert the Val element and return the iterator pointing to the element and a Boolean value to indicate whether the Val is successfully inserted.

Insert Val before the iterator LOC and return an iterator pointing to this element;

Insert the elements returned from the iterator start to end to the Set;

St. Erase (LOC)

St. Erase (START, end)

St. Erase (key_type key)

Delete the element indicated by Loc

Delete elements between [start, end)

Delete the elements whose key value is value and return the number of deleted elements.

St. Find (key_type key)

Returns an iterator pointing to an element whose key value is key. End () is not found ()

pair<iterator start, iterator end> equal_range(const key_type &key)

The interval between the elements whose key value is equal to the key is [start, end). The two iterators in the range are returned using pair.

St. lower_bound (key_type key)

St. upper_bound (key_type key)

Returns an iterator pointing to the first element> = Key

Returns an iterator pointing to the first element of> key.


Strtok Function

# Include <string. h>

Char * strtok (char * str1, constchar * str2 );

Function: returns the pointer to the part of str1 that is followed by the mark. str2 is the Separator Used as the mark. If the separator is not found, the function returns NULL. To convert a string into a tag, str1 is called for the first time as the tag separator. Therefore, all calls to str1 should be null.

Int main (){
Char STR [] = "smart, calm, luck ";
Char * P; P = strtok (STR ,",");
While (p ){
Printf ("% s \ n", P );
P = strtok (null ,",");
}
Return 0;
}
Running result:
Smart
Calm
Luck


Question:

Count the total number of different words in an article.


Sample Input
You are my friend

You are my friend you are my friend
#

Sample output
4

4


#include <cstdio>#include <cstring>#include <set>#include <string>#include <iostream>using namespace std;set<string> dict;int main(){    char str[10000];    string s;    while(gets(str)){        if(str[0]=='#') break;        dict.clear();        char *p; p = strtok(str," ");        while(p){            s = p;            dict.insert(s);            p = strtok(NULL," ");        }        printf("%d\n", dict.size());    }    return 0;}


HDU 2072 words, set, strtok

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.