使用者工具

網站工具


cpp:homework:hw5answer

國立屏東商業技術學院 資訊工程系 物件導向程式設計

參考解答


using namespace std;
#include <iostream>
#include <string>
 
int main()
{
  string *str = new string [5];
 
  for(int i=0;i<5;i++)
  {
    cout << "Input" << i+1 << ": " ;
    getline(cin,str[i]);
  }
  cout << "Lexicographical Ordering..." << endl;
 
  for(int a=0; a<4 ;a++)
  {
    for(int b=a+1; b<5 ; b++)
    {
      if(str[a] >str[b])
      {
        string temp;
        temp = str[a];
        str[a] = str[b];
        str[b] = temp;
      }
    }
  }
  for(int i=0;i<5;i++)
  {
    cout << str[i] << endl;
  }
  return 0;
}

cpp/homework/hw5answer.txt · 上一次變更: 2019/07/02 15:01 (外部編輯)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki