POJ 2418 Hardwood Species

Source: Internet
Author: User

Hardwood SpeciesTime Limit: 10000 MS Memory Limit: 65536 KTotal Submissions: 14326 Accepted: 5814 Description Hardwoods are the botanical group of trees that have broad leaves, produce a fruit or nut, and generally go dormant in the winter. america's temperate climates produce forests with hundreds of hardwood species -- trees that share certain biological characteristics. although oak, maple and cherry all are types of hardwood trees, for example, they are different species. together, all the hardwood species represent 40 percent of the trees in the United States. on the other hand, softwoods, or conifers, from the Latin word meaning "cone-bearing," have needles. widely available US softwoods include cedar, fir, hemlock, pine, redwood, spruce and cypress. in a home, the softwoods are used primarily as structural lumber such as 2x4 s and 2x6 s, with some limited decorative applications. using satellite imaging technology, the Department of Natural Resources has compiled an inventory of every tree standing on a particle day. you are to compute the total fraction of the tree population represented by each species. input to your program consists of a list of the species of every tree observed by the satellite; one tree per line. no species name exceeds 30 characters. there are no more than 10,000 species and no more than 1,000,000 trees. output Print the name of each species represented in the population, in alphabetical order, followed by the percentage of the population it represents, to 4 decimal places. sample Input Red packet handle invalid MapleWhite oak soft MapleRed oak Red oak white invalid WalnutWillowSample Output Ash 13.7931 Aspen 3.4483 Basswood 3.4483 Beech 3.4483 Black Walnut 3.4483 Cherry 3.4483 Cottonwood 3.4483 Cypress 3.44820.um 3.4483 Hackberry 3.4483 Hard Maple 3.4483 Hickory 3.4483 pecan 3.4483 Poplan 3.4483Red Alder 3.4483Red Elm 3.4483Red Oak 6.8966 Sassafras 3.4483 Soft Maple 3.4483 Sycamore 3.4483 White Oak 10.3448 Willow 3.4483 Yellow Birch 3.4483 Hint This problem has huge input, use scanf instead of cin to avoid time limit exceeded. source Waterloo Local 2002.01.26 is the tire tree, but this is very easy to make mistakes, because reading the sample he gave gives people an illusion, I think that the character is between A to Z a and z spaces. In fact, the question is not so mentioned. The name of A tree may have other characters. I can recognize this question. [cpp] # include <stdio. h> # include <string. h> # include <stdlib. h> char s1 [50]; struct tire {int tag; struct tire * next [300] ;}; struct num {char s1 [50]; int sum ;} a [1000010]; int top; int cmp (const void * e, const void * f) {struct num * p1, * p2; p1 = (struct num *) e; p2 = (struct num *) f; if (strcmp (p1-> s1, p2-> s1)> 0) {return 1 ;}else {return-1 ;}} int main () {struct tire * newnode (); int build (char s2 [50], struct tire * p); int I, j, n, m, t; double s; struct tire * head; head = newnode (); top = 0; s = 0; while (gets (s1) {t = build (s1, head ); s ++; if (t =-1) {a [top]. sum = 1; strcpy (a [top]. s1, s1); top ++;} else {a [t]. sum ++ ;}} qsort (a, top, sizeof (a [0]), cmp); for (I = 0; I <= top-1; I ++) {printf ("% s", a [I]. s1); printf ("%. 4lf \ n ", a [I]. sum * 100/s);} return 0;} struct tire * newnode () {int I; struct tire * p = (struct tire *) malloc (sizeof (struct tire); p-> tag =-1; for (I = 0; I <= 299; I ++) {p-> next [I] = NULL;} return p;} int build (char s2 [50], struct tire * p) {int I, l = strlen (s2), s; for (I = 0; I <= L-1; I ++) {www.2cto.com s = s2 [I]; if (p-> next [s] = NULL) {p-> next [s] = newnode ();} p = p-> next [s];} if (p-> tag =-1) {p-> tag = top; return-1;} return p-> tag ;}

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.