1024programmer Blog Achievement ranking (20)_qq_32300341’s blog

Achievement ranking (20)_qq_32300341’s blog

1004. Ranking (20)

time limit

400ms

memory limit

65536 kB

code length limit

8000B

Judgment procedure

Standard

author

CHEN, Yue

Read the names, student numbers, and grades of n students, and output the names of the students with the highest grades and the lowest grades respectively and student number.

Input format: Each test input contains 1 test case in the format of

 Line 1: positive integer n
   Line 2: the first student's name, student number, grade
   Line 3: The name of the second student Student ID Grade
   ... ... ...
   Row n+1: the nth student's name, student ID, grade
 

The name and student number are strings of no more than 10 characters, and the grade is an integer between 0 and 100. Here, it is guaranteed that no two students have the same grade in a set of test cases.

Output format: Output 2 lines for each test case, the first line is The name and student ID of the student with the highest grade, the second line is the name and student ID of the student with the lowest grade, with 1 space between the strings.

Sample input:

3
 Joe Math990112 89
 Mike CS991301 100
 Mary EE990830 95
 

Sample output:

Mike CS991301
 Joe Math990112
 
 
 
#include 
 #include
 using namespace std;
 /* run this program using the console pauser or add your own getch, system("pause") or input loop */


 int main(int argc, char** argv) {
  string n1;
   getline(cin,n1);
  int n;
  if(n1. length()==1)
  n=n1[0]-'0';
  else if(n1. length()==2)
  n=(n1[0]-'0')*10+n1[1]-'0';
  else
  n=(n1[0]-'0')*100+(n1[1]-'0')*10+(n1[2]-  '0');
  string s[1000];
  for(int i=0;i<n;i++)
   getline(cin,s[i]);
  int a[1000];
  for(int i=0;i<n;i++)
  {
  int j=0;
  int k=0;
  while(k!=2)
  {
  if(s[i][j]==' ')
  k++;
  j++;
  }
  j--;
  if(s[i].length()-j-1==3)
  a[i]=100;
  else if(s[i].length()-j-1==2)
  a[i]=(s[i][j+1]-'0')*10+(s[i][j+2]-  '0');
  else
  a[i]=(s[i][j+1]-'0');
  }




  int max=0,min=0;
  for(int i=1;i<n;i++)
  {
  if(a[i]>a[max])
  max=i;
  if(a[i]<a[min])
  min=i;
  }


  int i=0;
  int j=0;
  while(i!=2)
  {
  cout<<s[max][j];
  j++;
  if(s[max][j]==' ')
  i++;
  }
  i=0;
  j=0;
  cout<<endl;
  while(i!=2)
  {
  cout<<s[min][j];
  j++;
  if(s[min][j]==' ')
  i++;
  }
  return 0;
 }
 

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/achievement-ranking-20_qq_32300341s-blog/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索