33,311
社区成员
发帖
与我相关
我的任务
分享
#include<cstring>
#include<iostream>
using namespace std;
int main()
{ char a[20];
char *str=new char[20]; strcpy_s(a,"igeca");
strcat_s(a,"hfdjb");
strcpy_s(str,20,a);
cout<<"原无序的的数列为:"<<str<<endl;
char pt;
int i,j,k;
for(i=0;i<19;i++)
{ k=i;
for(j=i+1;j<20;j++)
if(str[i]>str[j])
k=j;
if(k!=i)
{ pt=str[k];
str[k]=str[i];
str[i]=pt;
}
}
for(i=0;i<20;i++)
cout<<"按降序规则排好序的新数列为:"<<str[i]<<endl;
system("pause");
}