题目描述
世界格局动荡不安,10国紧急召开会议磋商对策。有些国家斤斤计较,参会代表的座位如何排定争个不停。现在给他们按字典序排列,赶紧商议正事。请编写程序,为这10国的代表排好顺序。
输入
10个国家的名字,一个国家一行
输出
排好序的国家名,一个国家一行
问题及代码
#include<iostream>
#include<string>
using namespace std;
int main()
{
string temp;
string country[10];
int i,j;
for (i=0; i<10; i++)
{
cin>>country[i];
}
for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
if (country[j]>country[j+1])
{
temp=country[j];
country[j]=country[j+1];
country[j+1]=temp;
}
}
}
for (j=0; j<10; j++)
{
cout<<country[j]<<endl;
}
return 0;
}
运行结果