// One-star problem // Problem 10226 Hardwood Species /* This program is written by Prof. Chua-Huang Huang Department of Information Engineering and Computer Science Feng Chia University Taichung, Taiwan Disclaimer: The programming problem is downloaded from UVa Online Judge (https://uva.onlinejudge.org/). The program solution is provided for helping students to prepare Collegiate Programming Examination (CPE). The author does not guarantee the program is completely correct to pass UVa Online Judge platform or CPE examination platform. This program is not intended for a student to copy only. He/She should practice the programming problem himself/herself. Only use the program solution as a reference. The author is not responsible if the program causes any damage of your computer or personal properties. No commercial use of this program is allowed without the author's written permission. */ #include #include #include int main(void) { //No species name exceeds 30 characters. //There are no more than 10,000 species and no more than 1,000,000 trees. char trees[10000][31]; int tree_count[10000]; // Count the number of species. char new_tree[31]; // A new tree to be added to trees[]. char c; // An input character. int length; // Length of new_tree string. int species; // Number of species found. int total; // Total number of trees. int cases; // Number of testing cases. int new_line = 0; // Indicate a new line has been started. int case_done; // As case is completed. int i, j, k; // Loop variables. scanf("%d", &cases); // Input the number of cases, skip two newline. scanf("%c%c", &c, &c); // Ignore the two newlines. for (i=0; i=j; k--) { // Shift the rest of the species one position to the right. strcpy(trees[k+1], trees[k]); tree_count[k+1] = tree_count[k]; } strcpy(trees[j], new_tree); // Insert the name of the new species to position j. tree_count[j] = 1; // Species 1 has one tree. species++; // Increase the number of species. break; // Stop the loop. } } if (j==species) { // The new species is at the end of the species list. strcpy(trees[j], new_tree); // Insert the tree name of the end of the species list. tree_count[j] = 1; // The new species has one tree. species++; // Increase the number of species. } new_line = 1; } else { // A blank line is encountered. The end of the case is reached. for (j=0; j