Simple string sorting

Source: Internet
Author: User

Description

Enter the names and scores of 10 students on the keyboard. Sort the names of the Students in lexicographically Ascending Order and output the results (the relationship between the names and scores remains unchanged ).

Input

Enter 11 rows in total. Each row in the first 10 rows is the name of a student, and the last row is 10 integers separated by spaces to indicate the corresponding scores of 10 students.

The output table lists the students' names and scores in Lexicographic Order. There are 10 rows in total. Each student's name and score occupies one row. The names and scores are separated by commas. Sample Input
BushWhiteMarkJeanBlackWoodJennyFrankBillSmith78 85 96 65 46 83 77 88 54 98
Sample output
Bill,54Black,46Bush,78Frank,88Jean,65Jenny,77Mark,96Smith,98White,85Wood,83
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

# Include <stdio. h>
# Include <string. h>
Int main ()
{
Char a [11] [1, 120], B [2, 120];
Int q [10], p, w;
For (w = 0; w <10; w ++)
{
Gets (a [w]);
}
For (int w = 0; w <10; w ++)
{
Scanf ("% d", & q [w]);
}
For (int y = 0; y <10; y ++)
For (w = 1; w <10; w ++)
{
If (strcmp (a [W-1], a [w])> 0)
{
Strcpy (B, a [W-1]);
Strcpy (a [W-1], a [w]);
Strcpy (a [w], B );
P = q [w];
Q [w] = q [W-1];
Q [W-1] = p;
}
}
For (w = 0; w <10; w ++)
Printf ("% s, % d \ n", a [w], q [w]);
Return 0;
}

Related Article

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.