Problem B: 零起点学算法103——查找最大元素

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 9951  Solved: 4793

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)
代码如下:
#include<bits/stdc++.h>
using namespace std; int main(){
char a[101];
while(gets(a)!=NULL){
vector<char> b;
vector<char> c;
for(int i=0;i<(int)strlen(a);i++){
b.push_back(a[i]);
c.push_back(a[i]);
}
sort(b.begin(),b.end());
int max=b[(int)strlen(a)-1];
for(int i=0;i<strlen(a);i++){
cout<<c[i];
if(c[i]==max) cout<<"(max)";
}
cout<<endl;
} return 0;
}

这里要注意不能直接写成strlen(),要写成(int)strlen(),具体理解可以看看这篇文章https://blog.csdn.net/liujian20150808/article/details/50406601

ZSTUOJ刷题⑩:Problem B.--零起点学算法103——查找最大元素的更多相关文章

  1. Problem H: 零起点学算法103——查找最大元素

    #include<stdio.h> #include<string.h> int main() { ]; while(gets(a)!=NULL) { ]; ;a[i]!='\ ...

  2. Problem H: 零起点学算法109——单数变复数

    #include <stdio.h> #include<string.h> int main(void) { int n; ]; scanf("%d",&a ...

  3. Problem G: 零起点学算法106——首字母变大写

    #include<stdio.h> #include<string.h> int main(void) { ]; int i,k; while(gets(a)!=NULL) { ...

  4. Problem D: 零起点学算法95——弓型矩阵

    #include<stdio.h> #include<string.h> int main() { ][]; while(scanf("%d%d",& ...

  5. Problem F: 零起点学算法42——多组测试数据输出II

    #include<stdio.h> int main() { ; while(scanf("%d%d%d",&a,&b,&c)!=EOF) { ...

  6. Problem E: 零起点学算法34——3n+1问题

    #include<stdio.h> #include<math.h> int main() { int n; n<=pow(,); ; scanf("%d&qu ...

  7. Problem K: 零起点学算法107——统计元音

    #include<stdio.h> int main() { int n; ]; while(scanf("%d%*c",&n)!=EOF) { while(n ...

  8. Problem J: 零起点学算法105——C语言合法标识符

    #include<stdio.h> #include<ctype.h>//调用isalpha函数 int main() { int n; ]; while(scanf(&quo ...

  9. Problem I: 零起点学算法104——Yes,I can!

    #include<stdio.h> int main() { ]; while(gets(a)!=NULL) { printf("I am "); printf(&qu ...

  10. Problem G: 零起点学算法102——删除字符

    #include<stdio.h> #include<string.h> int main() { ],a; while(gets(ch)!=NULL) { scanf(&qu ...

随机推荐

  1. Vue2+Cesium1.9+热力图开发笔记

    1.安装cesiumJS.heatmap.webpack插件依赖包: yarn install/npm install "dependencies": { ... "ce ...

  2. jar包启动脚本, 以及外置配置文件application.yml

    想使用sh脚本来启动,停止,重启我们的jar服务, 顺便还要外置配置文件方便修改 示例server.sh如下,启动命令为sh server.sh start或restart或stop,修改其中的这几个 ...

  3. Android移动端性能测试工具mobileperf

    简介:mobileperf是阿里开源的一个python PC 工具,可以收集Android性能数据: cpu.内存.流畅度.fps.logcat日志.流量.进程线程数.进程启动日志,mobileper ...

  4. CAD中如何将图形对象快速转换成三维曲面?

    天小编将接着上节内容给大家分享浩辰CAD软件中将图形对象快速转换成三维曲面的相关操作技巧,感兴趣的小伙伴可以和一起来了解一下哦! CAD中将图形转换为曲面的操作步骤: 1.用浩辰CAD软件中打开图纸后 ...

  5. Hyper-V虚拟机在Win2019server中共用一个公网IP

    Hyper-V虚拟机在Win2019server中共用一个公网IP 有时生产环境中希望一台宿主机上的多台虚拟机共用一个IP出口,按以下操作处理即可. 环境: Windows 2019 server D ...

  6. python func_timeout 设置函数超时退出

    使用func_timeout设置函数超时退出,使用func_set_timeout装饰器和func_timeout方法 from func_timeout import func_set_timeou ...

  7. css布局、动画要点

    background属性 属性解释background属性是css中应用比较多,且比较重要的一个属性,它是负责给盒子设置背景图片和背景颜色的,background是一个复合属性,它可以分解成如下几个设 ...

  8. cv::flip

    int main(int argc, char** argv) { cv::namedWindow("Example 2-3", cv::WINDOW_AUTOSIZE); cv: ...

  9. ComPiler200003:Story-Oriented Programming

    Story-Oriented Programming MAY 25TH, 2018 http://www.brandonkeown.com/2018/05/story-oriented-program ...

  10. Echarts中国地图下钻

    //各省份的地图json文件 var provinces = { '上海': '/asset/get/s/data-1482909900836-H1BC_1WHg.json', '河北': '/ass ...