华为笔试之字符串旋转
来源:互联网 发布:中国遥感卫星数据现状 编辑:程序博客网 时间:2024/06/05 17:56
时间:2014.04.08
地点:基地二楼
说明:这些练习尽量按Google C++标准规范编写,环境 VS2013,语言:C++11
--------------------------------------------------------------------------------
一、题目
输入一串字符串(长度最大为100),可能包括小写字母、大写字母,数字、其他符号等等。要求将小写字母变成下一个字母(a—->b, b—->c),但是小写z变成小写A(这就是旋转的意思啦!),大写字母也变成大写字母的下一个字母(如A—>B,B—->C……..),但是大写Z变成大写A。大写字母变完还是大写字母,小写字母变完还是小写字母。数字和其他符号不变。
输入样例:abcABCz@123
输出样例:bcdBCDa@123
#include<iostream>#include<string>#include<cctype>#include<cassert>using namespace std;string StringRotation(const string& str);//Preconditon: The input string's lenth is not more than 100//Postcondition: Return a rotation string with an transfer:a->b,b->c...// z->a and A->B,B->C...Z->A.Other characters are remain.//Library facilities used:cassert,stringint main(){string input_str = "", out_str = "";cout << "Please input a string whitch you want to process:"<<endl;cin >> input_str;out_str = StringRotation(input_str);cout << "The input string \"" << input_str << "\"" << " after rotation is: " <<endl<< out_str << endl;return EXIT_SUCCESS;}string StringRotation(const string& str){assert(str.length() <= 100);string result_str = "";for (auto ch : str){if (isalpha(ch)){if (ch == 'z' || ch == 'Z')result_str += ch - 25;elseresult_str += ch + 1;}elseresult_str += ch;}return result_str;}
0 0
- 华为笔试之字符串旋转
- 华为笔试之字符串过滤
- 华为笔试题之字符串压缩
- 2016华为校招旋转字符串
- 华为笔试之最长单词
- 【逃离华为之面试、笔试】
- 华为笔试-字符串拆分和排序
- 华为笔试初级题目-字符串反转
- 【c++】【2015华为笔试】分解字符串
- 华为笔试题,关于操控字符串
- 字符串之旋转词
- LintCode之旋转字符串
- 算法之旋转字符串
- 华为笔试之CDkey的生成
- 华为上机笔试题之约瑟夫环
- 华为oj之字符串反转
- 华为oj之字符串分割
- 华为笔试
- 【顺时针打印矩阵】
- shell——cat,find,xargs,tr,sort,grep
- 独角戏
- 003
- Android Mms专题之:信息发送流程
- 华为笔试之字符串旋转
- Oracle sqlplus 常用设置
- 1
- c语言中static用法总结
- Oracle 数据库实例启动关闭过程
- Java 读取文件
- ReportStudio入门教程(十七) - 将汇总显示在第1行
- POJ 3046
- 从零开始,使用python快速开发web站点(1)