20220210 º¹½À
1.³¼ö¸¦ ÀÔ·ÂÇÏ¿© ¹è¿¿Ï¼º
int randNum=(int)(Math.random()*100)+1;
(1~100±îÁöÀÇ ³¼ö Ãâ·Â)
2.Á¤·Ä
(¼±ÅÃÁ¤·Ä ¾Ë°í¸®Áò »ç¿ë)
3.À̺а˻öÀ¸·Î ãÀ» °ªÀÇ À§Ä¡¸¦ Ãâ·Â
import static java.lang.Math.*;
import java.util.*;
class T0210_34 //À̺Р°Ë»ö ¾Ë°í¸®Áò
{
static void Sort(int[] Arry){
int K;
//int i=0,J=0
//int i=0,J=0;
//i=0,J=1; J´Â i¿¡ ¿µÇâÀ» ¹Þ´Â´Ù~
int i=-1,J;
int cnt1=0,cnt2=0;
System.out.println("ÀüüȸÀü¼ö: "+ cnt2+" ȸÀü¼ö "+cnt1+" : "+Arry[0]+"-"+Arry[1]+"-"+Arry[2]+"-"+Arry[3]+"-"+Arry[4]+"-"+Arry[5]+"-"+Arry[6]+"-"+Arry[7]+"-"+Arry[8]+"-"+Arry[9]);
System.out.println("=================================");
do{
cnt1=cnt1+1;
i=i+1;
J=i; //8-1
do{
cnt2++;
//[0][1][2][3][4]
J = J + 1; //1,2,3,4
//¿À¸§Â÷¼ø > 1,2,3,4,5
//³»¸²Â÷¼ø < 5,4,3,2,1
if(Arry[i] > Arry[J]){ //Arry[0] > Arry[1]
K = Arry[i];
Arry[i] = Arry[J];
Arry[J] = K;
}
System.out.println("ÀüüȸÀü¼ö: "+ cnt2+" ȸÀü¼ö "+cnt1+" : "+Arry[0]+"-"+Arry[1]+"-"+Arry[2]+"-"+Arry[3]+"-"+Arry[4]+"-"+Arry[5]+"-"+Arry[6]+"-"+Arry[7]+"-"+Arry[8]+"-"+Arry[9]);
//System.out.println("ÀüüȸÀü¼ö "+cnt2);
}while(J<=8);
}while(i<=7);
}
static void makeRandom(int[] DATA)
{
int i=-1;
int cnt=0;
while(cnt<10){
i++;
cnt++;
int randNum=(int)(Math.random()*100)+1;//1~100±îÁöÀÇ ³¼ö
DATA[i]=randNum;
}
}
public static void main(String[] args) //À̺а˻ö
{
int L,H,M;
int[] DATA = new int[]{0,0,0,0,0,0,0,0,0,0};
makeRandom(DATA);
Sort(DATA);
Scanner s = new Scanner(System.in);
System.out.println("1ºÎÅÍ 100±îÁö ¼ýÀÚ Áß °Ë»öÇÒ ¼ýÀÚ¸¦ ÀÔ·ÂÇϽÿÀ");
int J = s.nextInt();
L=0;
H=9;
while(true)
{
if(L <= H)
{
M = (int)((H+L)/2);
if(J != DATA[M])
{
if(J>DATA[M]){
L=M+1;
}else{
H=M-1;
}
} else {
System.out.println("ÀԷ°ª: "+J+", À§Ä¡: "+M);
break;
}
} else {
System.out.println("ÀԷ°ª: "+J+", À§Ä¡: NOT FOUND");
break;
}
}
}
}
³Ñ°Ü¹ÞÀº ¼ýÀÚ¸¸Å ÆäÀÌÁö(Ç¥ Ä)´Ã¸®±â & ÆäÀÌ¡ ¸Å±â±â
/study/t0210.html
·Î±×ÀÎ ÆäÀÌÁö ¸¸µé±â
/study/login.html