Problem Description
对于输入的每个字符串,查找其中的最大字母,在该字母后面插入字符串“(max)”。
Input
输入数据包括多个测试实例,每个实例由一行长度不超过100的字符串组成,字符串仅由大小写字母构成。
Output
对于每个测试实例输出一行字符串,输出的结果是插入字符串“(max)”后的结果,如果存在多个最大的字母,就在每一个最大字母后面都插入”(max)”。
Sample Input
abcdefgfedcba
xxxxx
Sample Output
abcdefg(max)fedcba
x(max)x(max)x(max)x(max)x(max)
解题思路:这道题只是考察ASCII码表的简单题目,个人开始以为它的重点是处理相差32的大小字母(把A与a看成等值, 不过事实证明这不是他的重点,会导致题意理解错误)
/*
author : Yangchengfeng
*/
#include<stdio.h>
#include<string.h>
#define N 100
int main()
{
char str[N];
while(scanf("%s", str)!=EOF){
int len = strlen(str);
int i = 0;
char tempStr = str[0];
for(; i<len; i++){
if(str[i] > tempStr){
tempStr = str[i];
}
}
for(i=0; i<len; i++){
printf("%c", str[i]);
if(str[i] == tempStr){
printf("(max)");
}
}
printf("\n");
}
return 0;
}
第一次的错误:
/*
author : Yangchengfeng
*/
#include<stdio.h>
#include<string.h>
#define N 100
int main()
{
char str[N];
while(scanf("%s", str)!=EOF){
int len = strlen(str);
int i = 0;
char letter = 'a';
char tempStr;
for(; i<len; i++){
if(str[i] >= 'A' && str[i] <= 'Z'){
tempStr = str[i] + 32;
} else {
tempStr = str[i];
}
if(letter < tempStr){
letter = tempStr;
}
} // 理解错题意
for(; i<len; i++){
printf("%c", str[i]);
if(str[i] == letter || str[i] + 32 == letter){
printf("(max)");
}
}
printf("\n");
}
return 0;
}