POJ 2418 Hardwood Species (Application of map in STL), pojhardwood

Source: Internet
Author: User

POJ 2418 Hardwood Species (Application of map in STL), pojhardwood

Address: POJ 2418

I found a lot of information through this question .. I know a lot of things I didn't know before ....

Comment out the description in the code.

The Code is as follows:

# Include <iostream> # include <cstdio> # include <string> # include <cstring> # include <stdlib. h> # include <math. h> # include <ctype. h >#include <queue >#include <map> # include <algorithm> using namespace std; int main () {map <string, int> mp; // declare a map container, which is an object map <string, int>: iterator cnt; // declare a map iterator, which is a pointer int sum = 0; char s [40]; while (gets (s) {sum ++; mp [s] ++;} for (cnt = mp. begin (); cnt! = Mp. end (); cnt ++) // by default, the system is sorted in ascending order, this Code uses an iterator (that is, pointer 0 traverses {double x; x = cnt-> second * 100.0/sum from start to end in map; // second indicates the second element of the iterator, that is, the int-type number printf ("% s %. 4lf \ n ", cnt-> first. c_str (), x); // first indicates the first element of the iterator, that is, the string. // It is stored as a string in the iterator and needs to be converted to % s using. c_str (). printf cannot output a string and must be converted. } 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.