返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     string name[5]={"大雄","小叮噹","宜靜","技安","阿福"};
  8. int score[5]={60,80,100,40,75};
  9. cout<<"原始資料"<<endl;
  10. cout<<"--------------------"<<endl;
  11. cout<<"姓名\t成績"<<endl;
  12. cout<<"--------------------"<<endl;
  13. for(int i=0;i<4;i++)
  14. {
  15.         for(int j=i+1;j<5;j++)
  16.         {
  17.         if(score[i]<score[j])
  18.         {
  19.         int tmp1;
  20.         tmp1=score[i];
  21.         score[i]=score[j];
  22.         score[j]=tmp1;
  23.         string tmp2;
  24.         tmp2=name[i];
  25.         name[i]=name[j];
  26.         name[j]=tmp2;
  27.         
  28.         }
  29.         }
  30.         }
  31.         for(int i=0;i<5;i++)
  32. cout<<name[i]<<"\t"<<score[i]<<endl;
  33. cout<<"依成績排序後資料"<<endl;
  34. cout<<"--------------------"<<endl;
  35. cout<<"姓名\t成績\t排名"<<endl;
  36. cout<<"--------------------"<<endl;
  37. for(int i=0;i<5;i++)
  38. cout<<name[i]<<"\t"<<score[i]<<"\t"<<i+1<<endl;
  39.     system("pause");
  40.     return 0;
  41. }
複製代碼

TOP

返回列表