目录
选择题
- 数据量越大,数据更新的操作对索引的效率影响越大
- 数量量很少的时候,全表扫描可能比索引检索数据更快
编程题
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的使用,对于字母不区分大小写