华为机试——字符串字母转换(二)
2015-11-26 16:03
288 查看
题目:输入一个字符串,将其中大写字母转换为对应小写字母之后的第五个字母,若原始大写字母为V~Z,则转换为对应小写字母的值减21。其他字符变换,输出转换后的字符串。例如,对于字母A,则转换为小写字符f;如形参是字母W,则转换为小写字母b。
样例输入:Axs3mWss
样例输出:fxs3mbss
#include<iostream> #include<string> #include<cctype> using namespace std; string convert(string s) { string::size_type i=0; string result; char ch; for(;i<s.size();i++) { if(isupper(s[i])) { if(s[i]>='V' && s[i]<='Z') { ch=tolower(s[i])+5-26; result.push_back(ch); } else { ch=tolower(s[i])+5; result.push_back(ch); } } else result.push_back(s[i]); } return result; } int main() { string str; getline(cin,str); cout<<convert(str)<<endl; }
相关文章推荐
- Face Alignment by Coarse-to-Fine Shape Searching
- WebX实践指南_请求处理(一)
- 百度地图SDK使用笔记
- redis安装
- C++primer plus第六版课后编程练习答案6.6
- 黑马程序员——java基础--网络编程
- php设计模式
- 实现mysql在windows server 2008下自动备份
- 快速搭建一个成熟,强壮的App框架【转载】
- 哈夫曼树
- HDU 5547 Sudoku
- C# 装箱和拆箱
- sqlserver2008创建数据库 报 Cannot read property is filestream 此属性不可用于sql server 7.0 解决
- PCL—低层次视觉—点云分割(RanSaC)
- LeetCode "Minimum Height Tree" !!
- 安卓开发之SQLite数据库用法
- T-SQL动态查询(3)——静态SQL
- Kafka集群安装
- 计算机网络常用知识
- sencha gridpanel 单元格编辑