/*
* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:李晓凯
* 完成日期:2014年 11 月 27 日
* 版 本 号:v1.0
*
* 问题描述:比较国家的大小(国家字母ASC码)并按 从小到大的顺序输出
* 输入描述:输入10个国家的名字
* 程序输出:从小到大的顺序输出国家的名字
*/
#include <iostream>
#include <string>
using namespace std;
int main()
{
int i,j;
string t,country[10];
for(i=0; i<10; ++i)
{
cin>>country[i];
}
for(i=0; i<9; ++i)
{
for(j=0; j<9-i; ++j)
{
if(country[j]>country[j+1])
{
t=country[j];
country[j]=country[j+1];
country[j+1]=t;
}
}
}
for(i=0; i<10; ++i)
{
cout << country[i]<<endl;
}
return 0;
}
学习总结:认识到了C++中独有的string字符串的直接比较,这比C语言更方便了!