第十四周 项目2-1,2

#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};
    cout<<"按成绩排:"<<endl;
    for(j=7;j>=0;j--)
        for(i=0;i<j;i++)
        if(score[i]>score[i+1])
    {
        t=score[i];
        score[i]=score[i+1];
        score[i+1]=t;
        temp=name[i];
        name[i]=name[i+1];
        name[i+1]=temp;
    }
     for(i=0;i<8;i++)
            cout<<"第"<<i+1<<"名:"<<name[i]<<endl;
            for(j=7;i>0;j--)
                for(i=0;i<j;i++)
                if(name[i]>name[i+1])
            {
                temp=name[i];
                name[i]=name[i+1];
                name[i+1]=temp;
            }
            cout<<"按姓名排:"<<endl;
            for(i=0;i<8;i++)
                cout<<"第"<<i+1<<"名:"<<name[i]<<endl;
     return 0;
}

第十四周 项目2-1,2_第1张图片

你可能感兴趣的:(第十四周 项目2-1,2)