1、前k个大写,后面的小写
import java.util.Scanner;
public class Main1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
String s=sc.next();
System.out.println(s.substring(0,k).toUpperCase()+s.substring(k).toLowerCase());
}
}
2、长城
输入
6
1 1 4 5 1 4
输出最小操作次数(151515最小)
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);
int n = sc.nextInt();
int[] a =new int[n];
for(int i = 0; i < n; i++){
a[i] = sc.nextInt();
}
if(n<=2) System.out.println(0);
int jishu=0;
int oushu=0;
int jishumax=0;
int oushumax=0;
Map<Integer,Integer> map1=new HashMap();
Map<Integer,Integer> map2=new HashMap();
int res=0;
//奇数
for(int i=0;i<n;i+=2){
if(map1.containsKey(a[i])){
map1.put(a[i],map1.get(a[i])+1);
if(jishumax<map1.get(a[i])){
jishumax=map1.get(a[i]);
jishu=a[i];
}
}else{
map1.put(a[i],1);
if(jishumax<map1.get(a[i])){
jishumax=map1.get(a[i]);
jishu=a[i];
}
}
}
//偶数
for(int i=1;i<n;i+=2){
if(map2.containsKey(a[i])){
map2.put(a[i],map2.get(a[i])+1);
if(oushumax<map2.get(a[i])){
oushumax=map2.get(a[i]);
oushu=a[i];
}
}else{
map2.put(a[i],1);
if(oushumax<map2.get(a[i])){
oushumax=map2.get(a[i]);
oushu=a[i];
}
}
}
for(int i=0;i<n;i+=2){
if(a[i]!=jishu) res++;
}
for(int i=1;i<n;i+=2){
if(a[i]!=oushu) res++;
}
System.out.println(res);
}
}
#京东笔试##笔经#