1.简写单词
题目链接:1037-简写单词_牛客竞赛语法入门班数组字符串习题
每次取出输出的首字母,如果首字母是小写,则将其变成大写输出,如果是大写,则直接输出
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scanner =new Scanner(System.in);
while(scanner.hasNext()){
char ch =scanner.next().charAt(0);
if(ch>='a' && ch<='z'){
ch=(char)(ch-32);
System.out.print(ch);
}else{
System.out.print(ch);
}
}
}
}
2.dd爱框框
题目链接:F-dd爱框框_牛客小白月赛34
由于本道题使用Scanner时会显示运行超时,所以我们需要自己定义一个快排
import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args)throws IOException{
Read scanner=new Read();
int n=scanner.nextInt();
int x=scanner.nextInt();
int left=1;
int right=1;
int ret=n;
int retleft=-1,retright=-1;
int[] array=new int[n+1];
int sum=0;
for(int i=1;i<=n;i++){
array[i]=scanner.nextInt();
}
while(right<=n){
sum+=array[right];
while(sum>=x){
if(right-left+1<ret){
retleft=left;
retright=right;
ret=right-left+1;
}
sum-=array[left++];
}
right++;
}
System.out.print(retleft+" "+retright);
}
}
class Read // 自定义快速读入
{
StringTokenizer st = new StringTokenizer("");
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String next() throws IOException
{
while(!st.hasMoreTokens())
{
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
String nextLine() throws IOException
{
return bf.readLine();
}
int nextInt() throws IOException
{
return Integer.parseInt(next());
}
long nextLong() throws IOException
{
return Long.parseLong(next());
}
double nextDouble() throws IOException
{
return Double.parseDouble(next());
}
}
3.除2 !
题目链接:除2!
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt(),k=scanner.nextInt();
PriorityQueue<Integer> heap=new PriorityQueue<>((a,b) ->{
return b-a;
});
long sum=0,x;
for (int i = 0; i < n; i++) {
x= scanner.nextLong();
sum+=x;
if(x%2==0){
heap.add((int)x);
}
}
while (!heap.isEmpty() && k--!=0){
long t= heap.poll()/2;
sum-=t;
if(t%2==0){
heap.add((int)t);
}
}
System.out.println(sum);
}
}
希望能对大家有所帮助!!!!!