package com.java.mytry;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeSet;
public class test7_3 {
/**
* 一个字符串可能包含a~z中多个字符,如有重复,求出现次数最多的那个字母及次数,如有多个重复的则都求出。
* @param args
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in) ;
String inputString = in.next();
doString(inputString);
}
public static void doString(String input) {
// TODO Auto-generated method stub
char[] chars = input.toCharArray(); //String转成一个个字符
ArrayList lists = new ArrayList(); //为了快速排序,再通过StringBuffer生成排序后的字符串
TreeSet set = new TreeSet(); //为了通过集合快速找到所有出现的字符串
for(int i = 0;i<chars.length;i++){
lists.add(String.valueOf(chars[i]));
set.add(String.valueOf(chars[i]));
}
System.out.println(set);
Collections.sort(lists); //Collections.sort(),对List排序。所出现字母排序
System.out.println(lists);
StringBuffer sb = new StringBuffer();
for(int i = 0;i<lists.size();i++){
sb.append(lists.get(i)); //拼接字符串
}
input = sb.toString();
System.out.println(input);
int max = 0;
String maxString = "";
ArrayList maxlist = new ArrayList();
int x= 0;
Iterator its = set.iterator(); //迭代器
while(its.hasNext()){ //检查序列是否有下一个元素
x++;
System.out.println(x+"*****");
String os = (String)its.next(); //获得序列下一个元素
int begin = input.indexOf(os);
int end = input.lastIndexOf(os);
int value = end-begin+1;
System.out.println("begin"+begin+" end"+end+" value"+value);
System.out.println();
if(value > max) {
max = value;
maxString = os;
maxlist.add(os);
}
else if(value == max){
maxlist.add(os);
}
}
int index = 0;
for(int i = 0;i<maxlist.size();i++){
if(maxlist.get(i).equals(maxString)){
index = i;
break;
}
}
System.out.println("max data");
for(int i = index;i<maxlist.size();i++){
System.out.println(maxlist.get(i) + " ; ");
}
System.out.println();
System.out.println("max" + max);
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeSet;
public class test7_3 {
/**
* 一个字符串可能包含a~z中多个字符,如有重复,求出现次数最多的那个字母及次数,如有多个重复的则都求出。
* @param args
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in) ;
String inputString = in.next();
doString(inputString);
}
public static void doString(String input) {
// TODO Auto-generated method stub
char[] chars = input.toCharArray(); //String转成一个个字符
ArrayList lists = new ArrayList(); //为了快速排序,再通过StringBuffer生成排序后的字符串
TreeSet set = new TreeSet(); //为了通过集合快速找到所有出现的字符串
for(int i = 0;i<chars.length;i++){
lists.add(String.valueOf(chars[i]));
set.add(String.valueOf(chars[i]));
}
System.out.println(set);
Collections.sort(lists); //Collections.sort(),对List排序。所出现字母排序
System.out.println(lists);
StringBuffer sb = new StringBuffer();
for(int i = 0;i<lists.size();i++){
sb.append(lists.get(i)); //拼接字符串
}
input = sb.toString();
System.out.println(input);
int max = 0;
String maxString = "";
ArrayList maxlist = new ArrayList();
int x= 0;
Iterator its = set.iterator(); //迭代器
while(its.hasNext()){ //检查序列是否有下一个元素
x++;
System.out.println(x+"*****");
String os = (String)its.next(); //获得序列下一个元素
int begin = input.indexOf(os);
int end = input.lastIndexOf(os);
int value = end-begin+1;
System.out.println("begin"+begin+" end"+end+" value"+value);
System.out.println();
if(value > max) {
max = value;
maxString = os;
maxlist.add(os);
}
else if(value == max){
maxlist.add(os);
}
}
int index = 0;
for(int i = 0;i<maxlist.size();i++){
if(maxlist.get(i).equals(maxString)){
index = i;
break;
}
}
System.out.println("max data");
for(int i = index;i<maxlist.size();i++){
System.out.println(maxlist.get(i) + " ; ");
}
System.out.println();
System.out.println("max" + max);
}
}