笔试强训第17天

目录

选择题

编程题 


选择题

  •  数据量越大,数据更新的操作对索引的效率影响越大
  • 数量量很少的时候,全表扫描可能比索引检索数据更快

编程题 

import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int arr[][]=new int[n+1][n+1];
        arr[1][1]=1;
        for(int i=2;i<=n;i++){
            arr[i][1]=1;
            for(int j=2;j<=n;j++){
                arr[i][j]=arr[i-1][j]+arr[i-1][j-1]+arr[i-1][j-2];
            }
        }
        boolean flag=true;
        for(int i=1;i<=n;i++){
            if(arr[n][i]%2==0){
                System.out.println(i);
                flag=false;
                break;
            }
        }
        if(flag){
            System.out.println(-1);
        }
    }
}

 

  • 不可以通过所有的用例,因为会有很大的数据量

有规律

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    /*
 1-  0            1
 2-  0            1 1
 3-  2            1 2 3
 4-  3            1 3 6 7
 5-  2            1 4 10 16 19
 6-  4            1 5 15 30 45 51
 7-  2            1 6 21 50 90 126 141
 8-  3            1 7 28 77 161 266 357 393
 9-  2            1 8 36 112 266 504 784 1016 1107
 10- 4            1 9 45 156 414 882 1554 2304 2907 3139
 
规律:
刨去前两行,每4行一个轮回,位数2,3,2,4循环;
     */
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int index = -1;
        if(n > 2){
            if((n-2) % 4 == 1 || (n-2) % 4 == 3){
                index = 2;
            }
            else if((n-2) % 4 == 2){
                index = 3;
            }
            else if((n-2) % 4 == 0){
                index = 4;
            }
        }
        System.out.println(index);
    }
}

package days.day17;

import java.util.*;
public class Main2{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        String str=sc.nextLine();
        String c=sc.nextLine();
        int count=0;
        for (int i = 0; i < str.length(); i++) {
            if (str.substring(i,i+1).equalsIgnoreCase(c)){
                count++;
            }
        }
        System.out.println(count);
    }
}
  •  关于equalsIgnoreCase的使用,对于字母不区分大小写
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

库里不会投三分

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值