Simple string sorting Time limit:5000ms Memory limit:100000k Title Description
Enter the names and scores of 10 students from the keyboard, arrange the names and outputs of the students in Dictionary order (the correspondence between names and grades remains the same).
Input
Enter a total of 11 lines, the first 10 rows is a student's name, the last line is 10 spaces separated by a number of integers to indicate the corresponding 10 student scores.
Output name the names and scores of the students are listed in dictionary order, a total of 10 lines, each student's name and score of one row, the name and results 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
Tips
Source
Sample Program
#include <iostream> #include <cstring> #include <algorithm>using namespace std;struct node{ Char NAME[10]; int grade;} STUDENT[10], T;int main () { int i, J; for (i=0; i<10; i++) { cin >> student[i].name; } for (i=0; i<10; i++) { cin >> student[i].grade; } For (i=0, i<9; i++) for (j=0; j<9-i; j + +) { if (strcmp (student[j].name,student[j+1].name) >0) { t = student[j]; STUDENT[J] = student[j+1]; Student[j+1] = t; } } for (i = 0; i < i++) cout << student[i].name<< "," <<student[i].grade<<endl; return 0;}
Simple string sorting