Results sort Ⅰ (simple sorting)

Mid-term exam is over, the teacher marking papers has been completed, but the teacher is too busy, and you want to write a program to all students achievement information to handle it, in accordance with the requirements of each student's grades in descending output information.

Input formats:

The first line of the input a n, n student representatives. Then there are n rows, the students are given a student number in each row num, name name, score score. The number of students 0 <n <= 1000, Science 11-bit integer, a string name, and a length of not more than 20, floating point performance, ensure that each student performance varies, and 0.0 <= score <= 100.0.

Output formats:

N output the results in descending order according to the line, each line to a space-separated output of the student's school number, name, score, score two decimal places.

Sample input:

Here we are given a set of inputs. E.g:

3
17031310135 hwf 85.5
16031310135 hww 98
15031310135 hff 78.5

Sample output:

Given here corresponding output. E.g:

16031310135 hww 98.00
17031310135 hwf 85.50
15031310135 hff 78.50
#include<iostream>
#include<cstdio>
using namespace std;
struct node
{
    char u[1010],v[1010];
    double w;
}a[1010];
int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        cin>>a[i].u>>a[i].v>>a[i].w;
       for(int i=0;i<n-1;i++)
            for(int j=i+1;j<n;j++)
       {
           if(a[i].w<a[j].w)
           {
             node b=a[i];
               a[i]=a[j];
               a[j]=b;
           }
       }
       for(int i=0;i<n;i++)
        printf("%s %s %.2lf\n",a[i].u,a[i].v,a[i].w);
    }
    return 0;
}

 

 

Guess you like

Origin www.cnblogs.com/dwj-2019/p/11356807.html