멍청이들

블로그 이미지
우린 멍청하니깐ㅋ
milang9

Article Category

분류 전체보기 (8)
멍청이들이란? (0)
오늘의 알고리즘 (1)
프로그래밍 참고 자료 (0)
진주의 배설물 (5)
교승이의 배설물 (1)
승하의 배설물 (1)

Recent Post

Recent Comment

Calendar

«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

Archive

My Link

  • Total
  • Today
  • Yesterday
  1. 2012.02.03
    [알고리즘] 2월 첫째주 알고리즘 - 3n+1
  2. 2012.02.03
    [PHP] 특정 아이피 차단
  3. 2012.02.03
    [C언어] 배열과 함수만을 이용한 Queue
  4. 2012.02.03
    [C언어] 2차원 배열 - 달팽이 알고리즘 -
  5. 2012.02.03
    [JavaScript] Math 함수를 이용한 계산기 프로그램 소스

제 소스는 이렇습니다~!


#include <stdio.h>

int main(void)
{
int min, max, cycle, maxcycle=0, n=0, i;

printf("Input : ");
scanf("%d%d",&min,&max);

for(i=min; i<=max; i++)
{
cycle=1;
n=i;
while(1)
{
if(n == 1)
{
if(cycle > maxcycle)
maxcycle = cycle;
break;
}

if(n%2 && n != 1)
{
n*=3; n++;
cycle++;
}

else if(n%2 == 0)
{
n/=2;
cycle++;
}

}
}

printf("Output : %d\n", maxcycle);

return 0;
and

<?

  $ip = array

        (

            " ???.???.???.?? "           // 아이피 주소

        );

 

  $block_user=0;

        if(in_array($HTTP_SERVER_VARS["REMOTE_ADDER"],$ip))

       {

            $block_user=1;

       }

 

        if($block=="1")

       {

            exit;
       }

       else

       {

            echo("");                  // reroad

       }
?>


차단해야할 값을 미리 선언해놓고
if문을 이용하여 지금 현재 사용자의 값과 차단해야할 값이 같으면 차단(exit) 다르면 리로드합니다.

반대로 특정한 사람만 사용하고 싶다면 어떻게 해야할까요?

분홍색 부분의 소스만

        if($block=="1")

       {

            echo("");
       }

       else

       {

            exit;

       }


이렇게 바꿔주면 됩니다!
 
참 쉽죠? ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
and

Queue 란? FIFO(First In First Out) 형식을 가진 자료구조 형태입니다!

간단하게 소스한번 볼까요~? 

#include <stdio.h>

 

int ary[5]={0,};
int rear=-1;
int front=-1;

 

void init_Queue();
void InQueue();
void DeQueue();
void Print_Queue();
void All_Clear();

 

int main(void)
{
 int i;

 init_Queue();

 printf("Queue에 데이터를 입력합니다.\n");

//0~4까지 입력 

for(i=0; i<4; i++)
 {
  InQueue();
 }

 Print_Queue();

 printf("Queue에 데이터를 입력합니다.\n");

//5까지 입력, 오버플로우 확인 

 for(i=0; i<2; i++)
 {
  InQueue();
 }
 Print_Queue();

//0~4까지 삭제

 printf("Queue에 데이터를 삭제합니다.\n");

 for(i=0; i<4; i++)
 {
  DeQueue();
 }

 Print_Queue();

//5까지 삭제, 언더플로우 확인

 printf("Queue에 데이터를 삭제합니다.\n");

 for(i=0; i<2; i++)
 {
  DeQueue();
 }

 Print_Queue();

//스택 비움

 printf("Queue를 비웁니다..\n");

 All_Clear();

 Print_Queue();


 return 0;
}

 

 

void init_Queue()
{
 rear=-1;
 front=-1;
}

 

void InQueue()
{
 int num;
 rear+=1;

 if(rear>=5)
 {
  printf("Overflow!\n");
 }
 else
 {
 printf("Input : ");
 scanf("%d",&num);

 ary[rear]=num;
 }

}

 

void DeQueue()
{


 front+=1;

 if(front==rear)
 {
  printf("underflow!\n");
  All_Clear();
 }
 else{

 ary[front]=0;
 }

}


void Print_Queue()
{
 int i;

 for(i=0; i<5; i++)
 {
  printf("Queue Data : %3d\n",ary[i]);
 }
 printf("\n");
}

 

void All_Clear()
{
 int i;

 for(i=0; i<5; i++)
 {
  ary[i]=0;
 }

 init_Queue();

}


엄청나게 지저분한걸 보면 딱 제가 짠 소스라는걸 알수있습니다..
필요하다면 메인 부분만 수정해서 쓰시면 될 것 같네요.
 
 
and


먼저 소스를 보여드리기에 앞서, 달팽이 알고리즘에 대해 설명해드릴게요.




1  2  3           1   2   3   4           1    2     3    4     5  

8  9  4          12  13  14  5          16   17   18   19    6

7  6  5          11 16  15  6           15   24   25   20   7

                  10     8   7         14    23  22   21   8

                                             13   12   11   10    9

 
x3                        x4                           x5           



이해가 가시나요~?
어떤 특정한 n을 입력받고, 빙글빙글 돌아 숫자를 넣어주면 됩니다!
애니고 컴퓨터게임제작과에서 출제되었던 문제로 기억합니다.

무려 중학교 때 짰었던 고대 자료네요~ ^^


#include <stdio.h>

 

int main()
{

int ary[50][50];
int n, z, i, j, x=0, y=-1, turn=1;

int num=1;

 

printf("숫자입력 : ");
scanf("%d",&n);

z=n;

while(z!=0)
{

for(i=0; i<z; i++)

{

y+=turn;
ary[x][y]=num;
num++;

}

 

z--;

 

for(i=0; i<z; i++)
{

x+=turn;
ary[x][y]=num;
num++;

}

 

turn*=-1;


}

 

for(i=0; i<n; i++)
{

for(j=0; j<n;j++)
{

printf("%5d",ary[i][j]);

}

printf("\n");

}

 

return 0;

}

and


소스 결과 : http://dowob.wo.tc/calcu.html

Math 함수를 이용하여 간단하게 계산기를 만들어 보았습니다!


<html>

 <head>
  <title>계산기</title>
  <style type="text/css">
   .btn
   {
    width:35px;
    height:25px;
    text-align:center;
   }
   
   .btn2
   {
    width:100px;
    height:25px;
    text-align:center;
   }
   
   .numeric
   {
    color:#0000FF;
   }
   
   .operator
   {
    color:#00FF00;
   }
   
   .function
   {
    color:#FF0000;
   }
   
   .input
   {
    text-align:right;
   }
  </style>
  <script language="javascript">
   var num1 = 0, num2 = 0;
   var operator="";
   varobjInput=null;
   var flag=0;

   window.onload=function()
   {
    objInput=document.getElementById("inputBox");
    objInput.value="0";
   }

   function buttonclick(objButton)
   {
    var value=objButton.value;

    switch(value)
    {
     case"1":
     case"2":
     case"3":
     case"4":
     case"5":
     case"6":
     case"7":
     case"8":
     case"9":
      if(objInput.value=="0" || flag==1) objInput.value="";
      objInput.value+=value;
      flag=0;
      break;
     case"0":
      if(objInput.value=="0") break;
      objInput.value+=value;
      flag=0;
      break;
     case"+/-":
      if(objInput.value=="0") break;
      if(objInput.value.charAt(0)=='-')
      {
       objInput.value=objInput.value.substr(1);
      }
      else
      {
       objInput.value="-"+objInput.value;
      }
      break;
     case".":
      objInput.value+=".";
      break;
    }
   }

   function operation(objButton)
    {
     var op=objButton.value;
     operator=op;
     num2=0;

     if(objInput.value.indexOf(".")>=0)
     {
      num1=parseFloat(objInput.value);
     }
     else
     {
      num1=parseInt(objInput.value);
     }
     flag=1;
    }

    
   function func(objButton)
    {
     var op=objButton.value;
     if(op=="x^y")
     {
      operator=op;
      if(objInput.value.indexOf(".")>=0)
      {
       num1-parseFloat(objInput.value);
      }

      else
      {
       num1=parseInt(objInput.value);
      }
      num2=0;
      flag=1;
      return;
     }

     switch (op)
     {
      case "sin":
       var temp=(objInput.value.indexOf(".")>=0) ? parseFloat(objInput.value):parseInt(objInput.value);
       objInput.value=Math.sin(temp);
       break;

      case "cos":
       var temp=(objInput.value.indexOf(".")>=0) ? parseFloat(objInput.value):parseInt(objInput.value);
       objInput.value=Math.cos(temp);
       break;

      case "tan":
       var temp=(objInput.value.indexOf(".")>=0) ? parseFloat(objInput.value):parseInt(objInput.value);
       objInput.value=Math.tan(temp);
       break;
     }
    }

    function calc()
    {
     if(num2==0)
     {
      if(objInput.value.indexOf(".")>=0)
      {
       num2=parseFloat(objInput.value);
      }

      else
      {
       num2=parseInt(objInput.value);
      }
     }

     switch(operator)
     {
      case "+":
       num=num1+num2;
       break;
      case "-":
       num=num1-num2;
       break;
      case "*":
       num=num1*num2;
       break;
      case "/":
       num=num1/num2;
       break;
      case "x^y":
       objInput.value=Math.pow(num1,num2);
       num1=0;
       num2=0;
       operator="";
       flag=0;
       return;
     }
     objInput.value=num;
    }

    function init()
    {
     num1=0;
     num2=0;
     operator="";
     flag=0;
     objInput.value="0";
    }
   </script>
 </head>
 <body>
  <table border="0" cellpadding="3" cellspacing="0">
   <tr>
    <td colspan="3">
     <input type="text" id="inputBox" size=30 class="input" readonly>
    </td>
   </tr>
   <tr>
    <td colspan="3" align="center">
     <input type="button" value="Clear" class="btn2 numeric" onclick="init()">
     <input type="button" value="=" class="btn2 numeric" onclick="calc()">
    </td>
   </tr>
   <tr>
    <td>
     <table border="0" cellpadding="3" cellspacing="0">
      <tr>
       <td><input type="button" value="1" onclick="buttonclick(this)" class="btn numeric"></td>
       <td><input type="button" value="2" onclick="buttonclick(this)" class="btn numeric"></td>
       <td><input type="button" value="3" onclick="buttonclick(this)" class="btn numeric"></td>
      </tr>
      <tr>
       <td><input type="button" value="4" onclick="buttonclick(this)" class="btn numeric"></td>
       <td><input type="button" value="5" onclick="buttonclick(this)" class="btn numeric"></td>
       <td><input type="button" value="6" onclick="buttonclick(this)" class="btn numeric"></td>
      </tr>
      <tr>
       <td><input type="button" value="7" onclick="buttonclick(this)" class="btn numeric"></td>
       <td><input type="button" value="8" onclick="buttonclick(this)" class="btn numeric"></td>
       <td><input type="button" value="9" onclick="buttonclick(this)" class="btn numeric"></td>
      </tr>
      <tr>
       <td><input type="button" value="0" onclick="buttonclick(this)" class="btn numeric"></td>
       <td><input type="button" value="+/-" onclick="buttonclick(this)" class="btn numeric"></td>
       <td><input type="button" value="." onclick="buttonclick(this)" class="btn numeric"></td>
      </tr>
      </table>
    </td>
    <td>
     <table border="0" cellpadding="3" cellspacing="0">
      <tr>
       <td><input type="button" value="+" onclick="operation(this)" class="btn operator"></td>
      </tr>
      <tr>
       <td><input type="button" value="-" onclick="operation(this)" class="btn operator"></td>
      </tr>
       <td><input type="button" value="*" onclick="operation(this)" class="btn operator"></td>
      <tr>
       <td><input type="button" value="/" onclick="operation(this)" class="btn operator"></td>
      </tr>
     </table>
    <td>
     <table border="0" cellpadding="3" cellspacing="0">
      <tr>
       <td><input type="button" value="x^y" onclick="func(this)" class="btn function"></td>
      </tr>
      <tr>
       <td><input type="button" value="sin" onclick="func(this)" class="btn function"></td>
      </tr>  
      <tr>
       <td><input type="button" value="cos" onclick="func(this)" class="btn function"></td>
      </tr>
      <tr>
       <td><input type="button" value="tan" onclick="func(this)" class="btn function"></td>
      </tr>
 </body>
</html>

'진주의 배설물 > ' 카테고리의 다른 글

[PHP] 특정 아이피 차단  (0) 2012.02.03
and

Tag Cloud