字符统计
【问题描述】
给定一个只包含大写字母的字符串S ,请你输出其中出现次数最多的字母。
如果有多个字母均出现了最多次,按字母表顺序依次输出所有这些字母。
【输入格式】
一个只包含大写字母的字符串S .
【输出格式】
若干个大写字母,代表答案。
【样例输入】
BABBACAC
【样例输出】
AB
(才发现题看错了wdm)
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
Integer max = 0;
Map<Character,Integer> mp = new HashMap();
for(int i=0;i<str.length();i++)
{
if(mp.containsKey(str.charAt(i))){
int k = mp.get(str.charAt(i));
mp.remove(str.charAt(i));
mp.put(str.charAt(i),k+1);
}else{
mp.put(str.charAt(i),1);
}
}
str = mp.toString();
for(int i = 3;i < str.length(); i = i+5){
if((str.charAt(i))-'0' > max){
max = (str.charAt(i))-'0';
}
}
Character maxc = ' ';
for(int i = 3;i < str.length(); i = i+5){
if((str.charAt(i))-'0' == max){
if( maxc - str.charAt(i-2) < 0)
{
maxc = str.charAt(i-2);
}
}
}
System.out.println(maxc);
}
}
试题E: 求阶乘
【问题描述】
满足N! 的末尾恰好有K 个0 的最小的N 是多少?
如果这样的N 不存在输出1。
【输入格式】
一个整数K。
【输出格式】
一个整数代表答案。
【样例输入】
2
【样例输出】
10
(???)
import java.util.Scanner;
public class Main {
static long jiecheng(long n){
long t = n;
for(long i = 1;i < n; i++){
t *= (n-i);
}
return t;
}
static long ling(long a){
long k = 0;
long b = 0;
for(long i = 1;i < a;i*=10 ){
b = a%i;
if(b == 0){
k+=1;
}
}
k-=1;
return k;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long k = sc.nextLong();
boolean tt = false;
for(long i = 0;i<1000000000;i++){
if(ling(jiecheng(i)) == k){
tt = true;
System.out.println(i);
break;
}
}
if(!tt){
System.out.println(-1);
}
}
}
(不说了,GG了)