acm--simulation-Balloon occurrences--hdoj 1004--let the Balloon rise--water

Source: Internet
Author: User


Hdoj Title Address: Portal


Let the Balloon Rise Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) Total submission (s): 104731 Accepted Submission (s): 40328

Problem Description Contest Time again! How excited it was to see balloons floating around. But to tell you a secret, the judges ' favorite time was guessing the most popular problem. When the contest was over, they would count the balloons of each color and find the result.

This is the year that they decide to leave the lovely job to you.

Input input contains multiple test cases. Each test case is starts with a number n (0 < N <=) – The total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to lower-case letters.

A test Case with N = 0 terminates the-input and this-test case are not-to-be processed.

Output for each case, print the color of balloon for the most popular problem on a. It is guaranteed this there is a unique solution for each test case.

Sample Input

5 green red Blue Red Red 3 pink Orange Pink 0
Sample Output
Red Pink


Test instructions: Give you a lot of color balloons, want you to find the most frequently the color of the balloon, very simple water problem


#include <stdio.h>
#include <iostream>
#include <string.h>
#include <memory.h>
using namespace std;
int main () {
   int n;
   while (scanf ("%d", &n) &&n) {
      string str[1001];
      int result[1001];
      string S;
      memset (result,0,sizeof (Result));
      int index=0,i,j,k;
      GetChar ();
      for (i=0;i<n;i++) {
        getline (cin,s);
        int flag=1;
        for (j=0;j<index;j++) {
            if (str[j]==s) {
                result[j]++;
                flag=0;
                break;
            }
        }
        if (flag) {
           str[index]=s;
           index++;
        }
      }
      int re=-1;
      int temp;
      for (k=0;k<index;k++) {
         if (result[k]>re) {
            re=result[k];
            temp=k;
         }
      }
      cout<<str[temp]<<endl;
   }
}





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.