#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
int main(void){
string str[] = { "abc", "ac", "c", "abcd" };
int length = sizeof(str) / sizeof(str[0]);
for (int i = 0; i < length; i++)
{
for (int j = i+1; j < length; j++)
{
if (str[i].size()>str[j].size())
{
string temp = str[j];
str[j] = str[i];
str[i] = temp;
}
}
}
for (int i = 0; i < length; i++)
{
cout << str[i] << endl;
}
system("pause");
return 0;
}
字符串排序
最新推荐文章于 2024-03-20 23:18:43 发布