Find the largest element
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 22046 accepted submission (s): 12094
Problem description searches for the maximum letter of each input string and inserts the string "(max)" after the letter )".
Input data includes multiple test instances. Each instance consists of a string of no more than 100 characters in length. The string consists of only uppercase and lowercase letters.
Output outputs a line of strings for each test instance. The output result is the result of inserting the string "(max)". If there are multiple largest letters, insert "(max)" after each maximum letter )".
Sample Input
abcdefgfedcbaxxxxx
Sample output
abcdefg(max)fedcbax(max)x(max)x(max)x(max)x(max)
import java.io.BufferedInputStream;import java.util.*;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(new BufferedInputStream(System.in));while (sc.hasNextLine()) {String s = sc.nextLine();if (s.length() < 100) {int j = 0;for (int i = 0; i < s.length(); i++) {if (s.charAt(i) > s.charAt(j))j = i;}StringBuffer bu = new StringBuffer();for (int i = 0; i < s.length(); i++) {bu.append(s.charAt(i));if (s.charAt(i) == s.charAt(j))bu.append("(max)");}System.out.println(bu.toString());}}}}