描述: | 简要描述 字符替换,按照替换规则,将输入的字符串做转换;其它字符不作处理。
详细描述: 题目背景 字母的替换规则,如下所示,A被E替换,B被C替换,依次类推。 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z
|
#include <stdlib.h> #include "oj.h" char* CharReplace(char* pSourceChar) { if (pSourceChar == NULL) { return 0; } int temp = 0; char bigchar[] = { "ECFAJKLBDGHIVWZYMNOPQRSTUX" }; char smallchar[] = { "erwqtyghbnuiopsjkdlfazxcvm" }; int i = 0; for (i = 0; pSourceChar[i] != '\0'; i++) { if (pSourceChar[i] >= 'A'&&pSourceChar[i] <= 'Z') { temp = (pSourceChar[i] - 'A'); pSourceChar[i] = bigchar[temp]; } else if (pSourceChar[i] >= 'a'&&pSourceChar[i] <= 'z') { temp = (pSourceChar[i] - 'a'); pSourceChar[i] = smallchar[temp]; } } pSourceChar[i] = '\0'; return pSourceChar; }