SDUT-1525 Character Statistics 2 (java*) __java

Source: Internet
Author: User
Character Statistics 2Time limit:1000 Ms Memory limit:65536 KiB Submit statistic Problem Description

Enter an English sentence to output the most frequently occurring characters and the number of occurrences in the sentence. Input

The input data contains multiple test instances, each of which is an English sentence that is no more than 100 in length and occupies one row. Output

Line-by-row output the most occurrences of the characters in each sentence and the number of occurrences (if there are multiple characters, output only the smallest ASCII character). Sample Input

I am a student
a good programming problem
ABCD ABCD ABCD
Sample Output
A 2
o 4
a 2
Hint Source

Java Array initialization method: Java.util.Arrays.fill (array name, numeric)

Reference: https://blog.csdn.net/alenc/article/details/1500113

import java.util.*;
		public class Main {public static void main (string[] args) {Scanner input = new Scanner (system.in);  Char c[] = new char[] {' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' g ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' o ', ' P ', ' Q ', ' R ', ' s ', ' t ', ' u ', ' V ', ' w ', ' x ', ' y ', ' z ', ' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ', '
		', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z '};
			while (Input.hasnext ()) {char arr[] = Input.nextline (). ToCharArray ();
			int num[] = new int[52];
			Arrays.fill (num, 0); the//arrays.fill () method is only suitable for initializing an array with the same value.
			int sum = 0, t = 0; 
						for (int i = 0; i < arr.length. i++) {for (int j = 0; J <-J + +) {if (c[j] = = Arr[i]) {num[j]++;
							if (Num[j] > sum) {sum = Num[j];
						t = j;
						} if (num[j] = = SUM) {if (c[t] > c[j]) t = j;
					} break;
		}} System.out.printf ("%c%d\n", c[t], sum); }
	}
}



Related Article

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.