Google is one of the most famous Internet search engines which hosts and develops a number of Internet-based services and products. On its search engine website, an interesting button “I’m feeling lucky” attracts our eyes. This feature could allow the user skip the search result page and goes directly to the first ranked page. Amazing! It saves a lot of time. The question is, when one types some keywords and presses “I’m feeling lucky” button, which web page will appear? Google does a lot and come up with excellent approaches to deal with it. In this simplified problem, let us just consider that Google assigns every web page an integer-valued relevance. The most related page will be chosen. If there is a tie, all the pages with the highest relevance are possible to be chosen. Your task is simple, given 10 web pages and their relevance. Just pick out all the possible candidates which will be served to the user when “I’m feeling lucky”. |
The input contains multiple test cases. The number of test cases T is in the first line of the input file. For each test case, there are 10 lines, describing the web page and relevance. Each line contains a character string without any blank characters denoting the URL of this web page and an integer Vi denoting the relevance of this web page. The length of the URL is between 1 and 100 inclusively. (1<=Vi<=100) |
hint 答案:(c语言,运用了函数来输入,输出和查找,使结构简单化。) #include <stdio.h> #include <stdlib.h> #include <string.h> void input(char n[10][100],int m[10]) { int i; for(i=0; i<10; i++) scanf("%s%d",n[i],&m[i]); } int find(int n[10]) { int i,max; max=n[0]; for(i=1; i<10; i++) if(max<n[i])max=n[i]; return max; } void output(char n[10][100],int m[10],int k) { int i; for(i=0; i<10; i++) if(m[i]==k)printf("%s\n",n[i]); } int main() { char name[10][100]; int num[10]; int n,i,k,t; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) { input(name,num); k=find(num); printf("Case#%d:\n",i); output(name,num,k); } } return 0; } |