问题及代码:
/*
*Copyright (c) 2014,烟台大学计算机学院
*All gight reserved.
*文件名称:temp.cpp
*作者:曾建强
*完成时间:2014年12月1日
*版本号:v1.0
*问题描述:十个国家之间按首字母大小排序
*输入描述:十个国家的名称
*输出描述:排序好的十个国家名称i ji dai
*/
#include <iostream>
#include<string>
using namespace std;
int main()
{
int i,j;
string t;
string country_name[10];
for (i=0; i<10; ++i)
{
cin>>country_name[i];
}
for (j=0; j<10; ++j)
{
for (i=0; i<10; ++i)
{
if ((country_name[i]>country_name[i+1]))
{
t=country_name[i];
country_name[i]=country_name[i+1];
country_name[i+1]=t;
}
}
}
for (i=0; i<10; ++i)
{
cout<<country_name[i]<<endl;
}
return 0;
}
运行结果