H面试程序(27):字串转换
- //1 字串转换
- //问题描述:
- //将输入的字符串(字符串仅包含小写字母‘a’到‘z’),按照如下规则,循环转换后输出:a->b,b->c,…,y->z,z->a;
- //若输入的字符串连续出现两个字母相同时,后一个字母需要连续转换2次。
- //例如:aa 转换为 bc,zz 转换为 ab;当连续相同字母超过两个时,第三个出现的字母按第一次出现算。
- //要求实现函数:
- //void convert(char *input,char* output)
- //【输入】 char *input , 输入的字符串
- //【输出】 char *output ,输出的字符串
- //【返回】 无
- //40min
- //示例
- //输入:char*input="abcd"
- //输出:char*output="bcde"
- //输入:char*input="abbbcd"
- //输出:char*output="bcdcde"
- #include<stdio.h>
- #include<assert.h>
- void convert(char *input,char* output)
- {
- assert(input);
- assert(output);
- while(*input != '\0') //遍历整个字符数组
- {
- if(*input == *(input+1)) //当前字符和下一字符相同的情况
- {
- if(*input =='z') //因为字母‘z’的情况比较特殊,所以单独分开
- {
- *output = (*input-25);
- *(output+1) =(*input - 24);
- output = output + 2;
- input = input + 2;
- }
- else //
- {
- *output = (*input + 1);
- *(output+1) = (*input + 2);
- output = output + 2;
- input = input + 2;
- }
- }
- else //当前字符和下一字符不相同的情况
- {
- if(*input =='z')//因为字母‘z’的情况比较特殊,所以单独分开
- {
- *output++ = (*input-25);
- input++;
- }
- else
- {
- *output++ = (*input + 1);
- input++;
- }
- }
- }
- *output = '\0'; //记得在output后加上结束符号
- }
- int main( )
- {
- char input[] = "abbbcd";
- printf("%s\n",input);
- char output[100];
- convert(input, output);
- printf("%s\n",output);
- return 0;
- }
H面试程序(27):字串转换的更多相关文章
- H面试程序(10): 字符串包含问题
题目描述:判断第二个字符串中的元素是否都能在第一个字符串中找到: 注意:和字符串的字串的问题有所区别,如第一个字符串为 abcdefg,第二个字符串为 aaabc,第二个字串还是包含于第一个字符串 ...
- H面试程序(11): 判断字符串是否包含子串问题
题目描述: 如字符串str1为''abcdef''' 字符串str2为'' bc''; 则字符串str1中含有 ...
- H面试程序(28):字符串处理转换
//2 字符串处理转换 //问题描述: //在给定字符串中找出单词( “单词”由大写字母和小写字母字符构成, //其他非字母字符视为单词的间隔,如空格.问号.数字等等:另外单个字母不算单词): //找 ...
- H面试程序(12): 输出字符串中第一个只出现一次的字母
题目描述: 若字符串str为'' sbdddsbfc'',则输出 f; 若字符串str为''aabbccdd'',则输出:字符串str中的字符都出现两次以上 #include <stdio.h& ...
- H面试程序(29):求最大递增数
要求:求最大递增数 如:1231123451 输出12345 #include<stdio.h> #include<assert.h> void find(char *s) { ...
- H面试程序(15): 冒泡排序法
#include<stdio.h> #include<assert.h> void display(int * a, int n) { for(int i = 0; i < ...
- H面试程序(16): 简单选择排序
#include<stdio.h> #include<assert.h> void display(int * a, int n) { assert(a); for(int i ...
- H面试程序(4):翻转句子中单词的顺序 .
题目:输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变. 句子中单词以空格符隔开.为简单起见,标点符号和普通字母一样处理. 例如输入“I am a student.”,则输出“stude ...
- H面试程序(1)编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的 下一秒
编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一秒. 如输入 2004 年 12 月 31 日 23 时 59 分 59 秒,则输出 2005年 1 月 1 日 0 时 0 分 0 秒. ...
随机推荐
- 拔一拔 ExtJS 3.4 里你遇到的没遇到的 BUG(1)
本文从今天开始,我要做的就是不断的更新,不断的披露ExtJS 3.4的BUG并修复它.需要注意的是版本为3.4而不是4.0,因为4.0改动和变化比较大,所以不要对号入座. 嘿嘿,本人不怎么写东西,不过 ...
- SQL 处理空值
问题: 在数据库中经常会有为null和''的值的列,在查询的时候,我们需要将它们转化成有效的值. 解决方案: 在emp表中的comm注释有的为null有的为'',在查询的时候 我们希望没有注释的显示为 ...
- RecyclerView 小记
RecyclerView,是在v7包加入的,一个灵活的view可以展示巨大的数据集,类似于listview的viewholder复用已经优化好了. 语言是苍白的,代码是最生动的叙说: 布局: < ...
- JAVA泛型实现一个堆栈类
package com.xt.test; /** * 泛型实现堆栈,thinking in java中的例子 * * @author Administrator * * @param <T> ...
- Noip2013错误避免
很多的时候,我们会说,这道题我会做,算法想出来了,但是这里那里少了一些判断,导致一分未得,或是说变量名错误,或者说干脆是文件名错误.这些都不是理由,如果火箭发射半空爆炸,可以说是控制器中一个运算符错误 ...
- openStack deep dive,Retake Policy
Method of Payment: visa MasterCard American Express Discover
- 关于tableView的简单实例
关于tableCell选中颜色 //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionSty ...
- Android animation学习笔记之view/drawable animation
前一章中总结了android animation中property animation的知识和用法,这一章总结View animation和Drawable animation的有关知识: View ...
- https://github.com/coolnameismy/BabyBluetooth github上的一个ios 蓝牙4.0的库并带文档和教程
The easiest way to use Bluetooth (BLE )in ios,even bady can use. 简单易用的蓝牙库,基于CoreBluetooth的封装,并兼容ios和 ...
- EBS OAF 开发中的OAMessageRadioGroup控件
EBS OAF 开发中的OAMessageRadioGroup控件 (版权声明,本人原创或者翻译的文章如需转载,如转载用于个人学习,请注明出处:否则请与本人联系,违者必究) 简单介绍 RadioGro ...