Merge branch 'master' of http://bdgit.educoder.net/paj35t926/pnc9vmwqf
commit
8912fb989c
@ -0,0 +1,47 @@
|
||||
import edu.princeton.cs.algs4.In;
|
||||
import edu.princeton.cs.algs4.StdIn;
|
||||
import edu.princeton.cs.algs4.StdOut;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class BianrySearch {
|
||||
|
||||
|
||||
public static int rank(int k,int[] a){
|
||||
int lo=0;
|
||||
int hi=a.length-1;
|
||||
while(lo<=hi){
|
||||
int mid=(lo+hi)/2;
|
||||
if(k>a[mid]){
|
||||
lo=mid+1;
|
||||
}
|
||||
else if(k<a[mid]){
|
||||
hi=mid-1;
|
||||
}
|
||||
else{
|
||||
return mid;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void main(String args[]){
|
||||
|
||||
FileInputStream ins;
|
||||
//输入重定向
|
||||
try{
|
||||
ins = new FileInputStream("F:\\所有学习的课程资料\\算法\\课本例题代码数据/tinyT.txt");
|
||||
System.setIn(ins);
|
||||
}catch(Exception e){
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
|
||||
int[] whitelist=In.readInts(args[0]);
|
||||
Arrays.sort(whitelist);
|
||||
while(!StdIn.isEmpty()){
|
||||
int key=StdIn.readInt();
|
||||
if(rank(key,whitelist)<0)
|
||||
StdOut.println(key);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dell
|
||||
*/
|
||||
public class jjcc {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println(add(1,2));
|
||||
System.out.println(sub(1,2));
|
||||
System.out.println(mul(1,2));
|
||||
System.out.println(div(1,2));
|
||||
}
|
||||
public static double add(double a,double b)
|
||||
{
|
||||
return a+b;
|
||||
}
|
||||
public static double sub(double a,double b)
|
||||
{
|
||||
return a-b;
|
||||
}
|
||||
public static double mul(double a,double b)
|
||||
{
|
||||
return a*b;
|
||||
}
|
||||
public static double div(double a,double b)
|
||||
{
|
||||
return (double)a/b;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue