您的位置:首页 > 其它

蓝桥杯感悟+3天笔记

2016-03-20 19:34 411 查看
报名参加蓝桥杯的时候自信满满想着会好好学,然后一直拖到最后几天才真正的拿起题目看学习,今天刚比赛完,感觉就是GG

一直没准备好,懵懵懂懂的做了4个小时,下面放出学习的一些盲区知识点,当做笔记而已,权当不想把这资料弄丢了,

1、java智能提示

(1). 打开Eclipse,选择打开" Window - Preferences"。

(2). 在目录树上选择"Java-Editor-Content Assist",在右侧的"Auto-Activation"找到"Auto Activation triggers for java"选项。默认触发代码提示的就是"."这个符号。

(3). 在"Auto Activation triggers for java"选项中,将"."更改:.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

2.求最大公约数和最小公倍数

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
scanner.close();
System.out.print(getMaxNumber(a, b));

}
public static int getMaxNumber(int a,int b){
if(a<b){
int temp;
temp = a;
a = b;
b = temp;
}
if(a%b==0){
return b;
}else{
getMaxNumber(b, a%b);
}
return 0;

}

}

求m,n的最大公约数是k那么他们的最小公倍数是:m*n/k

求三个数的最小公倍数:先求两个数的最小公倍数q,然后再求q和第三个数的最小公倍数

3.定义常量 public static final double PI=3.14159265358979323;

4.怎么输出特定的格式小数点后几位 double s = r*r*PI;
DecimalFormat decimalFormat = new DecimalFormat("#.0000000");
System.out.print(decimalFormat.format(s));

5.求和公式 n*(n+1)/2

6.输入输出最好用流来操作

BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String string = null;
String string2 = null;
int sum = 0;
string = bufferedReader.readLine();
int n = Integer.parseInt(string);
string2 = bufferedReader.readLine();
String[] stringarray = string2.split(" ");

7.数组排顺序  Arrays.sort(date);传入的是一个数组 得到的是date[]数组从小到大的顺序

8.求一个数的各个位 各位m%10;

                    十位m/10%10

                    百位m/100%10
   千位m/1000%10

9.int temp[]=Arrays.copyOfRange(a, 0, 5)将数组a中的下标0到4复值打temp中

10.十进制转换成十六进制 Integer.toHexString(值)

                八进制  Integer.toOctalString(值)
二进制  Integerr.toBinaryString(值)

   十六进制转成十进制   Integer.valueOf("FFF",16).ToString();

          八进制
Integer.valueOf("876",8).ToString();
      二进制
Integer.valueOf("0110",2).ToString();

Integer.toHexString(m).toUpperCase()  变成大写的

11.A 65  a 96  0  48 字符数ch变成整数  ch-'0'或者ch-48 

12.学习快速排序

13.十六进制转换成十进制

package test;

import java.util.Scanner;

//System.out.println();

public class Main {

public static void main(String[] args)   {
Scanner scanner = new Scanner(System.in);
String string = scanner.nextLine();
char ch[] = string.toCharArray();
long sum=0;
int len = ch.length;
for(int i=0;i<len;i++){
if(ch[i]-'0'>=0&&ch[i]-'0'<=9){
sum+=(ch[i]-'0')*Math.pow(16, len-i-1);
}else{
sum += (ch[i]-'A'+10)*Math.pow(16, len-i-1);
}
}
System.out.println(sum);
}

}

14虽然通过BufferReader读取数据写起来比较麻烦,但是当遇到测试数字超级大的情况下 Scanner scanner = new Scanner(System.in)会读取不到数据的,所以还是通过BufferReader读取数据

15.全排列算法

package a;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.Scanner;

import javax.swing.InputMap;

public class sum {

public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
int[] str = {1,2,3};
f(str,0,2);
}

private static void f(int[] str, int first, int end) {
if(first==end){
for(int j=0;j<=end;j++){
System.out.print(str[j]);
}
System.out.println();
}
for(int i=first;i<=end;i++){//循环是从i=first开始的!!
swap(str,i,first);
f(str, first+1, end);
swap(str, i, first);
}
}

private static void swap(int[] str, int i, int first) {
int temp;
temp = str[i];
str[i] = str[first];
str[first] = temp;

}

}

16.数组中取出n个数的组合

package a;

public class sum {

public static void main(String[] args)  {

int [] a = {1,2,3,4};
f(a,2);
}
private static void f(int a[],int n){
if(a.length==0||a==null||n>a.length||n<=0)
return ;
int b[] = new int
;
g(a, n, 0, b, 0);

}
private static void g(int a[],int n,int begin,int b[],int index){
if(n==0){
for(int i=0;i<index;i++)//i<index!!
System.out.print(b[i]);
System.out.println();
return ;
}
for(int i=begin;i<a.length;i++){//遍历数组中的各个数
b[index] = a[i];
g(a, n-1, i+1, b, index+1);

}
}

}

                          
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: