[2025]:查找最大元素
来源:互联网 发布:广数980tdg71编程实例 编辑:程序博客网 时间:2024/05/24 00:20
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 100int 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 100int 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;}
0 0
- 2025 查找最大元素
- 2025 查找最大元素
- 2025 查找最大元素
- 2025 查找最大元素
- 2025 查找最大元素
- [2025]:查找最大元素
- 2025查找最大元素
- 2025 查找最大元素
- hdu 2025 查找最大元素
- HDU 2025 查找最大元素
- HDU 2025 查找最大元素
- HDU 2025 查找最大元素
- HDU 2025 查找最大元素
- HDU 2025 - 查找最大元素
- hdu-2025-查找最大元素
- [hdu 2025] 查找最大元素
- HDUJ 2025 查找最大元素
- HDU 2025 查找最大元素
- PHP GIF 动画缩略图
- HashMap和Hashtable的区别
- 优秀博客一览
- hibernate标准查询
- 各主板U盘启动热键
- [2025]:查找最大元素
- waf实现扫描器识别
- storm文档(8)----配置文件说明
- 深入浅出解析C++中Vector容器
- redis configuration
- java阅读源码工具
- storm文档(9)----消息处理保证机制
- 一些第三方库的功能模块及使用的技术
- 读程序员面试-java多线程1