C++primer 11.1-day exercise

Source: Internet
Author: User

Exercise 11.1

Map He is an orderly and element-repeating associative container, and the way in which he stores elements is stored in the form of key-value pairs;

There are no special requirements for vector containers.

Exercise 11.2

List is useful for adding deleted elements anywhere, because he is a doubly linked list;

Vectors are suitable for programs that require random access, can only add elements after the tail, and adding or removing elements at other locations is inefficient;

The deque is suitable for adding deleted elements at the end of the container and randomly accessing the program;

Map is a set of key-value pairs, he can be found in the simultaneous efficient access;

Set is a simple set of keywords that is most useful when you just want to know if a value exists.

Exercise 11.3

1#include <iostream>2#include <string>3#include <iostream>4#include <string>5#include <vector>6#include <algorithm>7#include <list>8#include <functional>9#include <iterator>Ten#include <fstream> One#include <map> A#include <Set> - using namespacestd; - using namespaceplaceholders; the  - intMain () - { -Ifstreaminch("Title.txt"); +     stringstr; -map<string, size_t>Word_count; +     Set<string> exclude{"a"," an" }; A      while(inch>>str) at     { -         if(Exclude.find (str) = =exclude.end ()) -++Word_count[str]; -     } -      for(ConstAuto &w:word_count) -     { incout << W.first <<"occurs"<< W.second << ((W.second >1) ?" Times":" Time") <<Endl; -     } toSystem"Pause"); +     return 0; -}

Exercise 11.4

1#include <iostream>2#include <cctype>3#include <string>4#include <iostream>5#include <string>6#include <vector>7#include <algorithm>8#include <list>9#include <functional>Ten#include <iterator> One#include <fstream> A#include <map> -#include <Set> - using namespacestd; the using namespaceplaceholders; -  - string&change (string&s); - voidDelete_punct (string&s); +  - intMain () + { A     //Ifstream in ("Title.txt"); at     stringstr; -map<string, size_t>Word_count; -     Set<string> exclude{"a"," an" }; -      while(Cin >> str)//there is an error reading the file here, the reason is unknown -     { -         if(Exclude.find (str) = =exclude.end ()) in++Word_count[change (str)]; -     } to      for(ConstAuto &w:word_count) +     { -cout << W.first <<"occurs"<< W.second << ((W.second >1) ?" Times":" Time") <<Endl; the     } *System"Pause"); $     return 0;Panax Notoginseng } -  the string&change (string&s) + { A      for(Auto i =0; I! = S.size (); ++i) the     { +         if(Isupper (S[i])) -S[i] =ToLower (S[i]); $         if(Ispunct (S[i]))//the input punctuation here will be error, temporarily consider the flow input mode of CIN, to be resolved $S.erase (I,1); -     } -     returns; the}

C++primer 11.1-day exercise

Related Article

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.