有5个字符串,要求把字符串从小到大顺序排列,用string方法。
string s[5];
int a=4 ,b=0;
for(int i=0;i<5;i++){
cin>>s[i];
}
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++){
if(s[j]>s[j+1]){
string temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
}
for (int i=0;i<5;i++){
cout << s[i] << " " ;
}
本文提供了一个使用双重for循环实现的字符串排序示例程序,通过比较和交换的方式将5个输入的字符串按字典顺序进行排序。
1548

被折叠的 条评论
为什么被折叠?



