#include
#include
using std::cin;
using std::cout;
using std::string;
using std::endl;
int main()
{
const unsigned int NUM = 10; //字符串数量
string strArray[NUM];
string str;
for(unsigned int i = 0;i < NUM; ++i)
{
cout << "Please input string " << i << ":" << endl;
cin >> str;
int j;
for(j = i - 1; j >= 0; --j) //升序排序,插入排序原理
{
if (strArray[j].length() >= str.length())
{
strArray[j + 1] = strArray[j];
}
else
{
break;
}
}
strArray[j + 1] = str;
}
//输出
cout << "升序输出" << endl;
for (int i = 0; i < NUM; ++i)
{
cout << strArray[i] << endl;
}
system("pause"); //VC6.0中不用加这句
}
#include
#include
#include
#include
#include
using namespace std;
inline void eatline(){
while('\n'!=getchar())
;
}
int main(){
vectorvec;
for(int i=0; i<10; i++){
char s[80]={'\0'};
cin.get(s, 80);
eatline();
vec.push_back(s);
}
sort(vec.begin(), vec.end());
for(vector::iterator it=vec.begin(); it cout << *it << endl;
}