程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> hdu 1004,hdu

hdu 1004,hdu

編輯:關於C語言

hdu 1004,hdu


自從   暑假 ACM集訓之後就再也沒有碰過  ACM了   以前說出去的話都是潑出去的水啊  哈哈哈  

水一道題啊   一年過去了   

 

 

Problem 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     思路就是:一個字符型二維數組用來存顏色,一個一維整數型數組用了存顏色出現的次數。之後再拿第一個顏色掃一遍,遇見相同的count++,再拿第二個顏色掃一遍,這個用兩個for語句。        菜的摳腳啊     水不出來還是抄到其他人的思路的......  
 1 #include <stdio.h>
 2 #include <string.h>
 3 int main()
 4 {
 5     int n,max,i,j;
 6     char a[1000][15],b[1000];
 7     while(scanf("%d",&n)&&n)
 8     {
 9         for(i=0; i<n; i++)
10         {
11             scanf("%s",&a[i]);
12             b[i]=0;
13         }
14         for(i=0; i<n; i++)
15         {
16             for(j=i+1;j<n;j++)
17                 if(strcmp(a[i],a[j])==0)
18                     b[i]++;
19         }
20         max=0;
21         for(i=0;i<n;i++)
22             if(max<b[i])
23                 max=i;
24         printf("%s\n",a[max]);
25     }
26     return 0;
27 }

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved