當前位置:成語大全網 - 新華字典 - c++ 將壹個字符串數組中的若幹個字符串,字典序重新排列存儲並輸出。只要補充完整就可以了

c++ 將壹個字符串數組中的若幹個字符串,字典序重新排列存儲並輸出。只要補充完整就可以了

#include <iostream>

#define N 5

using namespace std;

int main()

{

int i,j,n=N;

char str[N][80]={"English","Math","Computer","Physics","Database"};

char mystring[80];

//字符串排序

for(i=0;i<N;i++)

{

for(j=i;j<N;j++)

{

if(strcmp(str[i],str[j])>0)

{

strcpy(mystring,str[i]);

strcpy(str[i],str[j]);

strcpy(str[j],mystring);

}

}

}

//輸出排序後的字符串

cout<<"sorted strings:"<<endl;

for(i=0;i<n;i++)

cout<<str[i]<<endl;

return 0;

}