#include<iostream.h> #include<string.h> int sort(char *book[],int num) { int i,j; char *temp; for(j=1;j<=num-1;j++) for(i=0;i<num-1-j;i++) if(strcmp(book[i],book[i+1])>0) { temp=book[i]; book[i]=book[i+1]; book[i+1]=temp; } return 0; } int main() { int i,n; char *book[10]; char a[10]; cout<<"请输入字符串数量:"; cin>>n; cout<<"请输入字符串:"<<endl; for(i=0;i<n;i++) { cin>>a; book[i]=a; } sort(book,n); for(i=0;i<n;i++) cout<<book[i]<<endl; return 0; }
onemoo
相关分类