华为2016校招机试题(2015年9月) 海大下午场(包含实现代码,运行环境为VS2010)

23 篇文章 0 订阅

描述:输入5个国名,并按字母顺序排列后输出
运行时间限制:无限制
内存限制:无限制
输入:输入5个国家名(英文大写),以空格分隔
输出:输出排序后的国名列表
样例输入:CHINA AMERICA AUSTRALIA FRANCE GERMAN
样例输出:
AMERICA
AUSTRALIA
CHINA
FRANCE
GERMAN

#include<iostream>
#include<string>

using namespace std;

const int num = 5; //国家的数目

int main()
{
    string country[num];
    int i,j;

    //输入国家的名字
    for( i = 0; i<num; i++  )
    {
        cin >> country[i];
    }

    //以国家的名字排序
    string temp;
    for ( j = 0; j < num - 1; j++ )
    {
        for ( i = 0; i < num - 1 - j; i++ )
        {
            if( country[i] > country[i + 1])
            {
                temp = country[i];
                country[i] = country[i + 1];
                country[i + 1] = temp;
            }
        }

    }

    //输出排序后的国家的名字
    for( int i = 0; i<num; i++ )
        cout<< country[i] <<endl;

    system( "pause" );

    return 0;
}

字母旋转
描述:把给定字符串中所有的英文字母改写成该字母在英文字母表中的下一个字母并输出。如:字母a改成字母b,字母z改写成字母a,大写仍为大写字母,小写字母仍为小写字母
运行时间限制:60sec
内存限制:256MByte
输入:输入的字符串,长度不超过100
输出:输出的字符串
样例输入:qaz123@THIS
样例输出:rba123@UIJT

#include<iostream>
#include<string>
using namespace std;

int main()
{
    string str;
    cin >> str;

    for( int i = 0; i<str.length(); i++ )
    {
        if( str[i] >= 'a' && str[i] <'z' )
            str[i] = str[i] + 1;
        if( str[i] == 'z' )
            str[i] = 'a';

        if( str[i] >= 'A' && str[i] <'Z' )
            str[i] = str[i] + 1;
        if( str[i] == 'Z' )
            str[i] = 'A';

    }
    cout<< str <<endl;

    system( "pause" );
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值