cpp:homework:hw4answer
國立屏東大學 資訊工程系 物件導向程式設計
hw1-4 參考解答
using namespace std;
#include <iostream>
#include <cstring>
int main()
{
char **str = new char * [5];
for(int i=0;i<5;i++)
{
str[i] = new char[21];
cout << "Input" << i+1 << ": " ;
cin.getline(str[i],21);
}
cout << "Lexicographical Ordering..." << endl;
for(int a=0; a<4 ;a++)
{
for(int b=a+1; b<5 ; b++)
{
if(strcmp(str[a],str[b])>0)
{
char temp[21];
strcpy(temp,str[a]);
strcpy(str[a],str[b]);
strcpy(str[b],temp);
}
}
}
for(int i=0;i<5;i++)
{
cout << str[i] << endl;
}
return 0;
}
cpp/homework/hw4answer.txt · 上一次變更: 2019/07/02 15:01 (外部編輯)
