static String days[]={"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THUSDAY","FRIDAY","SATURDAY"};
static Hashtable<String,Integer>hash=new Hashtable<>();
static{
int i=0;
while(i<days.length){
hash.put(days[i].substring(0,2),i);
++i;
}
}
public static void main(String[] args) {
int i=0;
int l=10000000;
int r,o;
long ts=System.currentTimeMillis();
while(i<l){
r=Rand.sti.nextInt(7);
o=getIndexOfDay0(days[r]);
++i;
}
long te=System.currentTimeMillis();
te-=ts;
System.out.println("time:"+te);
}
static final int[]trick0={
4,6,5,0,0
,3,0,0,0,0
,0,0,0,1,0
,0,0,0,0,0
,2
} ;
public static int getIndexOfDay1(String someday){
String key=Character.toUpperCase(someday.charAt(0))+""+Character.toUpperCase(someday.charAt(1));
return hash.get(key);
}
public static int getIndexOfDay0(String someday){
char ch0=Character.toUpperCase(someday.charAt(0));
int ch1=Character.toUpperCase(someday.charAt(1));
ch1&=ch0;
ch1-=64;
return trick0[ch1];
}
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου