/* * 程序的版权和版本声明部分 * Copyright (c)2012, 烟台大学计算机学院学生 * All rightsreserved. * 文件名称: 2.cpp * 作 者:王立强 * 完成日期:2012 年12 月 15日 * 版本号: v1.03 * 输入描述:略 * 问题描述:略 * 程序输出:略 */ #include <iostream> #include<string> using namespace std; const int num=6; int main() { int i,j,t; char temp[20]; char name[num][20]={"fll","sy","qxw","jsc","dwp","wlq"}; double score[num]={1,2,3,5,6,100}; for(j=1;j<=5;j++) for(i=0;i<=5-j;i++) { if(score[i]>score[i+1]) { t=score[i]; score[i]=score[i+1]; score[i+1]=t; strcpy(temp,name[i]); strcpy(name[i],name[i+1]); strcpy(name[i+1],temp); } } cout<<"按成绩排序的同学名单:"<<endl; for(i=0;i<=5;i++) { cout<<name[i]; cout<<":"; cout<<score[i]; cout<<endl; } for(j=1;j<=5;j++) for(i=0;i<=5-j;i++) { if(strcmp(name[i],name[i+1])>0) { strcpy(temp,name[i]); strcpy(name[i],name[i+1]); strcpy(name[i+1],temp); t=score[i]; score[i]=score[i+1]; score[i+1]=t; } } cout<<"按姓名排序的名单:"<<endl; for(i=0;i<=5;i++) { cout<<name[i]; cout<<":"; cout<<score[i]; cout<<endl; } return 0; }