Sorting of postgraduate exams (1)

Source: Internet
Author: User
Tags sorted by name

Reprinted please indicate the source: dunni column http://blog.csdn.net/u012027907

Question 1202: Sorting

Time Limit: 1 second

Memory limit: 32 MB

Special question: No

Submit: 10071

Solution: 3549

Description:

Sorts and outputs the N numbers.

Input:

The first line contains an integer N (1 <=n <= 100 ).
The next row contains N integers.

Output:

There may be multiple groups of test data. For each group of data, the N integers after sorting are output, each of which is followed by a space.
The result of each group of test data occupies one row.

Sample input:
41 4 3 2
Sample output:
1 2 3 4 
Source:
July 2006
9 degrees onlinejudge offers: http://ac.jobdu.com/problem.php? PID = 1, 1202
# Include <stdio. h >#include <algorithm> using namespace STD; # define n 101int main () {int Buf [N], n, I; while (scanf ("% d ", & N )! = EOF) {// The number of inputs for (I = 0; I <n; I ++) {scanf ("% d", & Buf [I]); // enter each number} Sort (BUF, BUF + n); // sort by library function (I = 0; I <n; I ++) // output printf ("% d", Buf [I]); printf ("\ n");} return 0 ;}



Question 1061: Sorting of scores

Time Limit: 1 second

Memory limit: 32 MB

Special question: No

Submit: 10579

Solution: 2924

Description:

Data of N students is sorted by scores. If scores are the same, data is sorted by name in alphabetical order, if the names are in the same alphabetic order, the students are sorted by age and information about the N students is output.

Input:

There are multiple groups of test data. The first row of each group of input has an integer n (n <= 1000). The next n rows include the data of N students.
Data for each student includes the name (a string of no more than 100 characters), age (integer), and score (positive number less than or equal to 100 ).

Output:

Sort the student information by score. If the score is the same, the student information is sorted by name in alphabetical order.
Then output the student information in the following format:
Name age score

Sample input:
3abc 20 99bcd 19 97bed 20 97
Sample output:
bcd 19 97bed 20 97abc 20 99
Tip:

The alphabetic order of the student's name is case-sensitive, for example, a must be prior to a's letter order (because a's ASC code is smaller than a's ASC code ).

Source:
Questions about the vitality of computer research at Tsinghua University in 2000
# Include <stdio. h> # include <algorithm> # include <string. h> using namespace STD; # define Max 1001 # define M 101 typedef struct student {char name [m]; int age; int score ;}student; bool CMP (student, student B) {// sort by custom rules if (. score! = B. Score) return a. score <B. Score; int TMP = strcmp (A. Name, B. Name); If (TMP! = 0) return TMP <0; else return. age <B. age;} int main () {student STU [Max]; int I, n; while (scanf ("% d", & N )! = EOF) {for (I = 0; I <n; I ++) {// enter scanf ("% S % d", STU [I]. name, & STU [I]. age, & STU [I]. score);} Sort (Stu, Stu + N, CMP); // sort by custom rules for (I = 0; I <n; I ++) // output printf ("% S % d \ n", STU [I]. name, STU [I]. age, STU [I]. score);} return 0 ;}
Reprinted please indicate the source: dunni column http://blog.csdn.net/u012027907


Sorting of postgraduate exams (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.