HDU 2025 Max element search

Source: Internet
Author: User

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
For each input string, find the maximum letter and insert the string "(max)" after the letter )".

 

Input
The input data includes multiple test instances. Each instance consists of a string of up to 100 characters in length. The string consists of only uppercase and lowercase letters.

 

Output
Each test instance outputs a line of strings. The output result is the result after the string "(max)" is inserted. If there are multiple largest letters, insert "(max)" after each maximum letter )".

 

Sample Input
Abcdefgedcba
Xxxxx

Sample Output
Abcdefg (max) fedcba
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());}}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.