//
// main.m
// 基础题5
//
// Created by Gabriel He on 10/7/15.
// Copyright © 2015 Gabriel He. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
char str[100];
char result[100];
int counter=0;
scanf("%s", str);
for(int i=0; i<100; )
{
if(str[i]=='\0')
break;
for (char a='a'; a<122; a++) {
if(str[i]=='\0')
break;
if (str[i]>=48 && str[i]<=57) {
result[counter]=str[i];
counter+=1;
i++;
a--;
}else if (str[i]==(char)a)
{
result[counter]=str[i]+1;
counter+=1;
result[counter]=str[i]+2;
counter+=1;
result[counter]=str[i]+3;
counter+=1;
i++;
}
}
}
printf("%s\n", result);
}
return 0;
}
//这里用到for循环嵌套,内循环控制“行数”,外循环控制“列数”
//这道题主要是要能灵活运用数组元素的赋值来完成字符串的拼接,比如“result[counter]=str[i]+1”
//以及利用字符码值的运算来遍历26个字母,即“for(char a='a'; a<122; a++)”
//总之这题还是挺容易出错的,所以要善用调试中的watch
|
|