Swimming

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 3   Accepted Submission(s) : 2

Font: Times New Roman | Verdana | Georgia

Font Size:

Problem Description

In the 2012 London Olympics, Sun Yang, the young Chinese swimmer, wins 2 golden medals and breaks the world record of men's 1500m freestyle. As a Chinese, we are proud of him, and as a ACMer, we can do some simple research on the results show system of the swimming.
When the swimmer touches the edge of the destination, the system will show the fastest 3 swimmers' names and their place. If the swimmer only breaks(strictly less than) the Olympic Record(OR), the numbers shows the place will replaced by the word 'OR'. If breaking the World Record(WR), the numbers shows the place will replaced by the word 'WR'.
Now your task is very simple. Given the swimmers' result, show the winners on the screen.

Input

The first line contain an integer T, which indicates the number of the test cases, Each test case consists of 9 lines. The first line is the Olympic Record and the World Record of the game(in the format of MM:SS.ss), and the followed by 8 lines, each line is the name of the swimmer and his/her result. The swimmers' names are all in uppercase letters and contain no space, and the result is in the format of MM:SS.ss. More details in the Sample Input. (Suppose that all the results are different)

Output

For each test case, the output contains 3 lines, the place of the fastest 3 swimmers or 'OR' or 'WR' and their names. There is a blank line between each case.

Sample Input

1
14:38.92 14:34.14
COCHRANE 14:40.34
SUN 14:31.02
MELLOULI 14:40.98
MIKE 15:00.83
BOELDS 15:01.02
SAUHWDNLWH 14:55.55
COBCASM 14:53.22
LISOFN 14:51.00

Sample Output

WR SUN
2 COCHRANE
3 MELLOULI

代码1:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

struct node
{
   char name[20];
   char grade[20];    
}T[10];

bool cmp(node A,node B)
{
  return strcmp(A.grade,B.grade)<0; 
}

int main()
{
 int t;
 char s[20],ss[20];
 scanf("%d",&t);
 while(t--)
 {
   scanf("%s",s);
   scanf("%s",ss);
   for(int i=0;i<8;i++)
   {
   scanf("%s",T[i].name);
   scanf("%s",T[i].grade);     
   } 
   sort(T,T+8,cmp);
   for(int i=0;i<3;i++)
   {
      if(strcmp(T[i].grade,ss)<0)
   {
     printf("WR %s\n",T[i].name);        
   }    
   else if(strcmp(T[i].grade,s)<0)
   {
      printf("OR %s\n",T[i].name);    
   }
   else
   printf("%d %s\n",i+1,T[i].name);
   }
   printf("\n");
 }
 return 0;
}

 

代码2:

#include<stdio.h>
#include<algorithm>
using namespace std;
struct node
{
 char name[20];
 int a,b,c;    
}T[10];


bool cmp(node A,node B)
{
  if(A.a==B.a)
  {
    if(A.b==B.b)
 return A.c<B.c;
 else
 return A.b<B.b;     
  }
  else
  return A.a<B.a; 
}

int Fun(int a,int b,int c,int l,int m,int r)
{
  if(a<l)
  return 1;
  else if(a>l)
  return 0;
  else
  {
     if(b<m)
  return 1;
  else if(b>m)
  return 0;
  else
  {
    if(c<r)
    return 1;
    else
    return 0;
     }   
  }  
}

int main()
{
  int t;
  scanf("%d",&t);
  while(t--)
  {
     int l,m,r,ll,mm,rr;
  scanf(" %d:%d.%d ",&l,&m,&r);
  scanf("%d:%d.%d",&ll,&mm,&rr);
  int x,y,z;
  for(int i=0;i<8;i++)
  {
    scanf("%s",T[i].name);
    scanf("%d:%d.%d",&x,&y,&z);
    T[i].a=x;
    T[i].b=y;
    T[i].c=z; 
     }  
  sort(T,T+8,cmp);
  for(int i=0;i<3;i++)
  {
    if(Fun(T[i].a,T[i].b,T[i].c,ll,mm,rr))
    {
    printf("WR %s\n",T[i].name);
    continue;
    }
    else if(Fun(T[i].a,T[i].b,T[i].c,l,m,r))
    {
    printf("OR %s\n",T[i].name);
    continue;
    }
    else
    printf("%d %s\n",i+1,T[i].name);    
     }
  printf("\n");  
  }
  return 0; 
}

链接:http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=16638&pid=1007