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. flutter 多种情况tabbar高度问题,普通使用和嵌套使用高度问题(Tab)。

    众所周知tabbar的高度是不可改变的.比如我们普通的写一个tabbar. 先上效果图: 代码: Scaffold( appBar: AppBar( title: Text("TabBarD ...

  2. vue获取不到页面图片实际宽高

    在某些情况下需要页面图片的宽高,使用Image获取加载图片获取图片宽高时为0,是因为图片未加载完返回宽高为0 如果未获取到宽高需要使用定时器定时获取图片,直到获取到后再清除定时器 示例代码: // n ...

  3. 关于WPF的圆角

    失败案例 <Border CornerRadius="3" Width="100" Height="100"> <Stac ...

  4. Python矩阵作图库matplotlib的初级使用(2)

    基础介绍 matplotlib图形对象层级结构: 图形对象(figure) → 子图对象(axes) → 坐标轴对象(axis) → 定位器对象-刻度线(locator)/格式化器对象-刻度线标签(f ...

  5. php json_encode 斜杠 反斜杠 转义处理

    $data = str_replace("\\\\n", "\\n", \jsonEncode($data)); // \\n转为\n $data = str_ ...

  6. tool script to convert back slash

    Back slash is used in windows, which makes so many headache for me. Then an idea came to my mind. It ...

  7. ipmitool for windows下载网址

    ipmitool for windows版本下载网址 http://ipmiutil.sourceforge.net/

  8. Linux 查找并杀死进程

    1.查找包含java的所有进程 ps -ef | grep java 2.根据端口号查看进程号 lsof -i:8080 sudo lsof -i:8080 3.杀死进程 kill -9 proces ...

  9. JS字符串拼接的方法及性能比较

    一.+和+=str += "one" + "two";这段代码在运行过程中,会经历四个步骤:1.在内存中创建一个临时字符串2.将连接后的字符串"one ...

  10. pySpark RDD基本用法

    pySpark RDD基本用法 RDD的全称是:Resilient Distributed Dataset (弹性分布式数据集),它有几个关键的特性: RDD是只读的,表示它的不可变性. 可以并行的操 ...