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. docker 实现原理

    实现原理 docker虚拟化 的核心是需要解决两个问题,资源隔离与资源限制 虚拟机是通过硬件虚拟化技术,通过一个 hypervisor 层实现对资源的彻底隔离 容器则是通过操作系统级别的虚拟化技术,利 ...

  2. centos7.8 安装 redis5.0.2

    1.安装gcc依赖 redis是由C语言开发,因此安装之前必须要确保服务器已经安装了gcc,可以通过如下命令查看机器是否安装: gcc -v 如果没有安装则通过以下命令安装: yum install ...

  3. oracle 索引创建

    --查询表里的索引 select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.inde ...

  4. 微信小程序云开发使用Typescript

    1.首先参考陈希章@中国在微信小程序开发中使用Typescript中的内容了解相关的内容 2.按以下步聚进行设置 1)确认本机环境已安装npm.通过在安装目录下输入 npm --v 如返回具体的版本, ...

  5. QT4.8.6移植

    sudo apt-get install libx11-dev libxext-dev libxtst-dev 配置: ./configure --prefix=/opt/qt4.8.6 -opens ...

  6. linux合并bilibili下载的blv视频

    B站下载的学习视频,用python+sh合并处理,自己mark一下 手机bilibili下载了视频,想要搞到电脑上看,结果发现下载下来的都是文件夹里的一堆片段,仔细一看还是 .blv,脑那样啊! 在虚 ...

  7. vue请求插件axios响应拦截302

    axios.interceptors.response.use(function (response) { return response;}, function (error) { // 对请求错误 ...

  8. 使用Tablayout出现标题消失的原因:setupWithViewPager()的大坑

    TabLayout使用addTab方法添加标题,调用setupWithViewPager方法绑定ViewPager tabLayout.addTab(tabLayout.newTab().setTex ...

  9. Optional中的map函数和flatMap函数的区别

    今天在学scala的时候发现Option中有map和flatMap返回的都是Option,然后再java8中的Optional也存在这样两个函数,觉得有点多余.后来分析了一下,还是有存在的必要的. 1 ...

  10. 像MIUI一样做Zabbix二次开发(4)——乐维监控定制Zabbix的方法

    做监控源于我们早期做运维服务的必然需求,我们的愿望是基于Zabbix这个强大开源平台,结合实际一线运维工作的需要+ITIL等运维理论,做成类似MIUI一样的开发.易用.实用.人性和美观的全新的监控平台 ...