# Xiamen University oj1438 simple question, map

Source: Internet
Author: User
`# Include <iostream> # include <map> # include <string> # include <fstream> using namespace STD; int main () {Map <string, int> Tongji; map <string, int >:: iterator it; int shuru1 = 0; CIN >>> shuru1; ifstream ifs ("shuju.txt"); // ifs >>> shuru1; // string shuru2; int COUNT = 3 * shuru1; string rank [3]; while (count --) {CIN> shuru2; // ifs> shuru2; // It = Tongji. find (shuru2); If (IT = Tongji. end () {Tongji [shuru2] = 1; // Tongji. insert (pair <string, int> (shuru2, 1) ;}else {Tongji [shuru2] ++ ;}} int max_num; string max_str; For (INT I = 0; I <3; I ++) {max_num = 0; For (IT = Tongji. begin (); it! = Tongji. end (); It ++) {If (IT-> second> max_num) {max_str = it-> first; max_num = it-> second ;} else if (IT-> second = max_num) {If (IT-> first <max_str) {max_str = it-> first ;}} if (I = 2) {rank [2] = max_str; Tongji. erase (max_str);} else if (I = 0) {rank [0] = max_str; Tongji. erase (max_str);} else if (I = 1) {rank [1] = max_str; Tongji. erase (max_str) ;}} if (rank [0]> rank [1]) {string temp; temp = rank [0]; rank [0] = rank [1]; rank [1] = temp;} If (rank [0]> rank [2]) {string temp; temp = rank [0]; rank [0] = rank [2]; rank [2] = temp;} If (rank [1]> rank [2]) {string temp; temp = rank [1]; rank [1] = rank [2]; rank [2] = temp ;} cout <rank [0] <"" <rank [1] <"" <rank [2]; // system ("pause "); return 0 ;}`

Related Keywords:

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.