/*
*copyright(c) 2014,烟台大学计算机学院
*All rights reserved。
*文件名称:14周(二维数组成绩姓名排序)
*作者:王忠
*完成日期:2014.12.01
*版本号:v1.0
*
*问题描述:初始化同学的成绩,姓氏,按大小排序
*输入描述:无
*程序输出:按照姓名或者成绩大小排序并输出
#include <iostream> #include <string> using namespace std; const int num=8; int main() { int i,j,t; string temp; string name[num]={"zhao","qian","sun","li","zhou","wu","zheng","wang"}; double score[num]={79,84,65,89,60,92,78,56}; for (i=0;i<7;i++) for (j=0;j<7-i;j++) if (score[j]>score[j+1]) { t=score[j]; score[j]=score[j+1]; score[j+1]=t; temp=name[j]; name[j]=name[j+1]; name[j+1]=temp; } for (i=0;i<8;i++) { cout<<name[i]<<" "; } cout<<endl; for (i=0;i<8;i++) cout<<score[i]<<" "; return 0; }
时间: 2024-10-09 03:27:31