要求是:输入几行字符串,按长度从小到大输出
**
```
#include
#include
int main()
{int n,i,j;
cin >> n;
string st[100],temp;
for(i=0;i<n;i++)
{cin>>st[i];}
for(j=1;j<n;j++)
for(i=0;i<n-j;i++)
{if(sizeof(st[i])>sizeof(st[i+1]))
{temp=st[i];
st[i]=st[i+1];
st[i+1]=temp;}}
}
for(i=0;i<n;i++)
cout << st[i]<< endl;
return 0;
}
```**
代码参考:
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int main()
{
int n,i,j;
cin >> n;
string st[100],temp;
for(i=0;i<n;i++)
{
cin >> st[i];
}
for(j=1;j<n;j++)
{
for(i=0;i<n-j;i++)
{
if(st[i].length()>st[i+1].length())
{
temp=st[i];
st[i]=st[i+1];
st[i+1]=temp;
}
}
}
for(i=0;i<n;i++)
cout << st[i]<< endl;
system("pause");
return 0;
}
结果:
所以你的代码在哪?