码迷,mamicode.com
首页 > 其他好文 > 详细

第十四周OJ项目——国家的比较

时间:2014-11-27 18:33:59      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:c++

/*
 * 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;
}


 

bubuko.com,布布扣

学习总结:认识到了C++中独有的string字符串的直接比较,这比C语言更方便了!

第十四周OJ项目——国家的比较

标签:c++

原文地址:http://blog.csdn.net/qq_21385857/article/details/41548783

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!