0
点赞
收藏
分享

微信扫一扫

HDOJ--2025 查找最大元素问题

金刚豆 2022-08-16 阅读 50


​​查找最大元素问题​​

 


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)



import java.util.Scanner; 
public class Max {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
String str=sc.nextLine();
char Maxchar=str.charAt(0);
for(int i=1;i<str.length();i++){
if(Maxchar<str.charAt(i)){
Maxchar=str.charAt(i);
}
}
/** * replace和replaceAll * (1)、replace的參數是char和CharSequence,即可支持字符的替換, * 也支持字符串的替換。 * (2)、replaceALl的參數是regex,即基於規則表达式的替换 * 例如:replaceAll("//d","*")把一个字符所有的数组转换成星号 */
System.out.println(str.replaceAll(""+Maxchar, Maxchar+"(max)"));
}
}
}

 

举报

相关推荐

0 条评论