每日小练:Day6

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);
    }
}

希望能对大家有所帮助!!!!! 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值