o-15

    xiaoxiao2021-03-25  96

    Description Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result. This year, they decide to leave this lovely job to you. Input Input contains multiple test cases. Each test case starts with a number N (0 < N < 1000) -- 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 15 lower-case letters. A test case with N = 0 terminates the input and this test case is not to be processed. Output For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that 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 题意简述: 给你几组数据,让你寻找里面出现最多的那一个。 解题思路: 运用两重循环和一个整形数组,用来存储每个字符串所出现的次数。 解题细节: 注意是多组输入,而且注意不要超出范围。 代码: #include<bits/stdc++.h> using namespace std; const int t=1001; int main() { int i,m,n,j,k; int a[t]={0},max; vector<string>v; string s; while(cin>>n) { if(n==0) break; v.clear(); a[1000]={0}; k=0; for(i=0;i<n;i++) { cin>>s; v.push_back(s); } for(i=0;i<v.size();i++) { for(j=0;j<v.size();j++) { if(v[i]==v[j]) a[i]++; } } for(i=0;i<v.size();i++) { max=a[0]; if(a[i]>max) { max=a[i]; k=i; } } cout<<v[k]<<endl; } return 0; } 解题心得: 题目简单,有助于增强信心!
    转载请注明原文地址: https://ju.6miu.com/read-24368.html

    最新回复(0)