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. SpringBoot + Quartz 集成

    Quartz 应用启动加载集群配置 @Bean 注解交由 Spring BeanFactory 容器管理 @Bean public JobDetailFactoryBean testJobDetail ...

  2. ubuntu拨号上网与以太网

    拨号上网使用的是ppp协议,主机和主机之间是点对点连接的,通常使用掩码255.255.255.255的方式来表示一个点对点连接. 以太网:使用的以太网协议. 拨号上网和以太网是两个完全不同的东西,如果 ...

  3. 软件工程日报二——gradle的安装与环境配置

    昨天下载了android studio 今天想要进行学习的时候,发现还需要下载gradle 一.进入官网,https://gradle.org/,点击下载 二.进入下载界面 三.选择相应的版本,点击b ...

  4. 安卓app的签名打包

    今天学习了什么是Android程序的签名打包. Android APP都需要我们用一个证书对应用进行数字签名,不然的话是无法安装到Android手机上的,平时我们调试运行时到手机上时, 是AS会自动用 ...

  5. Camstar报错:cannot be accessed through null object reference at CDO 'xxx'

  6. ES 基础操作

    集群 健康值的三种状态 Green:所有索引的所有分片均可用 primary 和 replice 均可用. Yellow 至少有一个 replice不可以用, 但是所有的 primary 正常. Re ...

  7. update_base_x.txt

    update g_temp.test_baseset field_date = '20210101'::datewhere field_int = 6

  8. php集成环境包PhpStudy及部署网站

    一.介绍:  phpStudy 是一个PHP调试环境的程序集成包. 该程序包集成最新的Apache+PHP+MySQL+phpMyAdmin+ZendOptimizer,一次性安装,无须配置即可使用, ...

  9. composer disgnoize public key fail

    https://composer.github.io/pubkeys.html 还有这事, 太不可思议了哦.--怎么进去的, 真的不知道哦.

  10. Windows Defender 实时防护打不开,你的IT管理员已经限制对此应用一些区域的访问

    最近在使用电脑的时候,Windows Defender实时防护不能使用,一打开就自动关闭,并且显示 该页面不可用 你的IT管理员已经限制对此应用一些区域的访问,实时防护页面显示 正在使用其他防护软件. ...