- #include<iostream>
- using namespace std;
- int main()
- {
- int t;
- string name[5]= {"大雄","小叮噹","宜靜","技安","阿福"},n;
- int score[5]= {60,80,100,40,75};
- cout<<"原始分數:"<<endl<<" ----------"<<endl;
- for(int a=0; a<=4; a++)
- cout<<name[a]<<"\t"<<score[a]<<endl;
- cout<<endl<<"依成績排名:"<<endl<<" ----------"<<endl;
- for(int b=0; b<=4; b++)
- {
- for(int c=0; c<b; c++)
- {
- if(score[b]>score[c])
- {
- t=score[b];
- score[b]=score[c];
- score[c]=t;
- n=name[b];
- name[b]=name[c];
- name[c]=n;
- }
- }
- }
- for(int a=0; a<=4; a++)
- cout<<name[a]<<"\t"<<score[a]<<endl;
- return 0;
- }
複製代碼 |