LOTTO_VER2

언어2015. 8. 24. 20:57

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#define LOTTO_MAX_SIZE 45
#define LOTTO_MIN_SIZE 6
#define LOTTO_RESULT_SIZE 7
#define The_End 0
typedef int LOTTO_BALL;
////////////////////////////////////////////////////////
void LOTTO_BALL_SETTING(LOTTO_BALL*);
void LOTTO_RANDOM_RECOMMEND(LOTTO_BALL*, LOTTO_BALL[], LOTTO_BALL[]);
void LOTTO_(LOTTO_BALL**, int);
void LOTTO_AUTO(LOTTO_BALL**, LOTTO_BALL[], LOTTO_BALL[],int);
LOTTO_BALL LOTTO_BONUS(LOTTO_BALL*, LOTTO_BALL[], LOTTO_BALL*, LOTTO_BALL[]);
void LOTTO_MATCHING(LOTTO_BALL**, LOTTO_BALL*,const int);
////////////////////////////////////////////////////////
int main(void)
{
 srand((unsigned)time(NULL));
 LOTTO_BALL LOTTO[LOTTO_MAX_SIZE] = { 0, };//초기화
 LOTTO_BALL LOTTO_TEMP_[LOTTO_MAX_SIZE] = { 0, };//초기화
 LOTTO_BALL lotto_random_recommend[LOTTO_MIN_SIZE] = { 0, };//초기화
 LOTTO_BALL lotto[LOTTO_MIN_SIZE] = { 0, };
 LOTTO_BALL lotto_temp[LOTTO_RESULT_SIZE] = { 0, };
 int i, k,j;//index
 int result = 0;
 int count;
 int s;
 int l = 0;
 /////////////////////함수 호출///////////////////////////
 LOTTO_BALL_SETTING(LOTTO);//최초 1~45 setting
 LOTTO_RANDOM_RECOMMEND(lotto_random_recommend, LOTTO, LOTTO_TEMP_);
 lotto_temp[6] = LOTTO_BONUS(lotto_random_recommend, LOTTO, lotto_temp, LOTTO_TEMP_);
 ////////////////////////////////////////////////////////
 
 printf("몇 번 하시겠습니까??: ");
 scanf_s("%d", &count);
 LOTTO_BALL** LOTTO_S = NULL;
 LOTTO_S = (LOTTO_BALL**)malloc(sizeof(LOTTO_BALL*)*count);
 for (i = 0; i < count; i++)
 {
  LOTTO_S[i] = (LOTTO_BALL*)malloc(sizeof(LOTTO_BALL)*LOTTO_MIN_SIZE);
 }
 for (i = 0; i < count; i++)
 {
  for (j = 0; j < LOTTO_MIN_SIZE; j++)
  {
   LOTTO_S[i][j] = 0;
  }
 }
 printf("자동-> (1)번\n");
 printf("수동-> (2)번\n");
 i = 0;
 ///////////////////////////////////////////////////////
 while (result != count)
 {
  printf("입력[%02d]: ", i+1);
  scanf_s("%d", &s);
  if (s == 1)
  {
   LOTTO_AUTO(LOTTO_S, LOTTO, LOTTO_TEMP_, i);
  }
  else if (s == 2)
  {
   LOTTO_(LOTTO_S, i);
  }
  i++;
  result++;//최초:0 -> 그 후 +1, count하고 같아지면 종료
 }
 ///////////////////////////////////////////////////////
 
 printf("-----------------------------------\n");
 for (i = 0; i < count; i++)
 {
  for (k = 65 + l; k <= 65 + l; k++)
  {
   printf("%c           ", k);
  }
  for (j = 0; j < LOTTO_MIN_SIZE; j++)
  {
   printf("%02d  ", LOTTO_S[i][j]);
  }
  l++;
  printf("\n");
 }
 printf("-----------------------------------\n");
 printf("금액                        %d원\n", 1000 * count);
 printf("\n");
 
 
  
 //(2)당첨 번호
 printf("-----------------------------------\n");
 for (i = 0; i < LOTTO_RESULT_SIZE; i++)
 {
  if (i == LOTTO_RESULT_SIZE - 1)
  {
   printf(" +보너스 번호: ");
  }
  printf("%02d ", lotto_temp[i]);
 }
 printf("\n");
 printf("-----------------------------------\n");
 ////////////////////////////////////////////////////
 LOTTO_MATCHING(LOTTO_S, lotto_temp, count);
 
 return The_End;
}
////////////////////////////////////////////////////////
void LOTTO_BALL_SETTING(LOTTO_BALL* lotto_ball)
{
 int i;
 for (i = 0; i < LOTTO_MAX_SIZE; i++)
 {
  *(lotto_ball + i) = i + 1;//1부터 45까지 입력
 }
}
void LOTTO_RANDOM_RECOMMEND(LOTTO_BALL*lotto_r_r, LOTTO_BALL LOTTO[], LOTTO_BALL LOTTO_TEMP_[])
{
 int i, j;//INDEX
 int result;
 int temp_size = 45;//random number size
 int temp_exchange = 0;//bubble sort시 필요함
 int temp = 0;//배열에서 임시로 idex 값을 받음
 int temp_ball = 0;//배열에서 임시로 값을 받음
 int temp_size_max = LOTTO_MAX_SIZE;
 int temp_size_min = LOTTO_MIN_SIZE;
 for (i = 0; i < LOTTO_MAX_SIZE; i++)
 {
  LOTTO_TEMP_[i] = LOTTO[i];
 }
 for (i = 0; i < temp_size_min; i++)
 {
  temp = rand() % temp_size;
  temp_ball = LOTTO_TEMP_[temp];
  *(lotto_r_r + i) = temp_ball;
  for (j = temp; j < temp_size_max-1; j++)
  {
   LOTTO_TEMP_[j] = LOTTO_TEMP_[j + 1];
  }
  temp_size_max--;
  temp_size--;
 }
 //정렬(bubble sort)
 for (i = 0; i<LOTTO_MIN_SIZE-1; i++)
 {
  result = 0;
  for (j = 0; j < LOTTO_MIN_SIZE - 1; j++)
  {
   if (*(lotto_r_r + j) > *(lotto_r_r + (j + 1)))
   {
    temp_exchange = *(lotto_r_r + j);
    *(lotto_r_r + j) = *(lotto_r_r + (j + 1));
    *(lotto_r_r + (j + 1)) = temp_exchange;
    result = 1;
   }
  }
  if (result == 0)
  {
   break;
  }
 }
}
void LOTTO_(LOTTO_BALL** lotto, int count)
{
 
 int i,j;
 int result = 0;
 int temp_exchange = 0;
 printf(" 1 ~ 45 까지 6자리 숫자를 입력하세요: \n");
 
 for (i = 0; i < LOTTO_MIN_SIZE; i++)
 {
  scanf_s("%d", (*(lotto + count)+i));
 }
 
 //정렬(bubble sort)
 for (i = 0; i<LOTTO_MIN_SIZE - 1; i++)
 {
  result = 0;
  for (j = 0; j < LOTTO_MIN_SIZE - 1; j++)
  {
   if (*(*(lotto + count) + j) > *(*(lotto + count) + (j + 1)))
   {
    temp_exchange = *(*(lotto + count) + j);
    *(*(lotto + count) + j) = *(*(lotto + count) + (j + 1));
    *(*(lotto + count) + (j + 1)) = temp_exchange;
    result = 1;
   }
  }
  if (result == 0)
  {
   break;
  }
 }
}
void LOTTO_AUTO(LOTTO_BALL** lotto, LOTTO_BALL LOTTO[], LOTTO_BALL LOTTO_TEMP_[],int count)
{
 
 int i, j;//INDEX
 int result = 0;
 int temp_size = 45;//random number size
 int temp_exchange = 0;//bubble sort시 필요함
 int temp = 0;//배열에서 임시로 idex 값을 받음
 int temp_ball = 0;//배열에서 임시로 값을 받음
 int temp_size_max = LOTTO_MAX_SIZE;
 int temp_size_min = LOTTO_MIN_SIZE;
 for (i = 0; i < LOTTO_MAX_SIZE; i++)
 {
  LOTTO_TEMP_[i] = LOTTO[i];
 }
 for (i = 0; i < temp_size_min; i++)
 {
  temp = rand() % temp_size;
  temp_ball = LOTTO_TEMP_[temp];
  *(*(lotto + count) + i) = temp_ball;
    
  for (j = temp; j < temp_size_max - 1; j++)
  {
   LOTTO_TEMP_[j] = LOTTO_TEMP_[j + 1];
  }
  temp_size_max--;
  temp_size--;
 }
 
 
 //정렬(bubble sort)
 for (i = 0; i<LOTTO_MIN_SIZE - 1; i++)
 {
  result = 0;
  for (j = 0; j < LOTTO_MIN_SIZE - 1; j++)
  {
   if ( *(*(lotto +count)+j) > *(*(lotto +count)+(j + 1)))
   {
    temp_exchange = *(*(lotto + count) + j);
    *(*(lotto + count) + j) = *(*(lotto + count) + (j + 1));
    *(*(lotto + count) + (j + 1)) = temp_exchange;
    result = 1;
   }
  }
  if (result == 0)
  {
   break;
  }
 }
 
}
LOTTO_BALL LOTTO_BONUS(LOTTO_BALL* lotto, LOTTO_BALL LOTTO_[], LOTTO_BALL* lotto_temp, LOTTO_BALL LOTTO_TEMP_[])
{
 int i, j,k;
 int temp_ball = 0;
 int temp_size_max = LOTTO_MAX_SIZE;
 int temp_size_min = LOTTO_MIN_SIZE;
 for (i = 0; i < LOTTO_MAX_SIZE; i++)
 {
  LOTTO_TEMP_[i] = LOTTO_[i];
 }
 for (i = 0; i < LOTTO_MIN_SIZE; i++)
 {
  *(lotto_temp + i) = *(lotto+i);
 }
 for (i = 0; i < temp_size_min; i++)
 {
  for (j = 0; j <temp_size_max; j++)
  {
   if (*(lotto + i) == LOTTO_TEMP_[j])
   {
    for (k = j; k < temp_size_max - 1; k++)
    {
     LOTTO_TEMP_[k] = LOTTO_TEMP_[k + 1];
    }
    --temp_size_max;
   }
  }
 }
 temp_ball = LOTTO_TEMP_[rand() % temp_size_max];
 return temp_ball;
}
void LOTTO_MATCHING(LOTTO_BALL** MeLOTTO, LOTTO_BALL* Match_LOTTO, const int size)
{
 //*(*(lotto + count) + j)
 printf("당첨 확인을 시작합니다.\n");
 int i, j, k;
 int count = 0;
 int bonus_count = 0;
 for (i = 0; i < size; i++)
 {
  for (j = 0; j < LOTTO_MIN_SIZE; j++)
  {
   for (k = 0; k < LOTTO_MIN_SIZE; k++)
   {
    if (*(*(MeLOTTO + i) + j) == *(Match_LOTTO + k))
    {
     count++;
    }
    if (*(*(MeLOTTO + i) + j) == *(Match_LOTTO + LOTTO_RESULT_SIZE-1))
    {
     bonus_count=1;
    }
   }

  }
  printf("입력번호:");
  for (j = 0; j < LOTTO_MIN_SIZE; j++)
  {
   printf("%02d ", (*(*(MeLOTTO + i) + j)));
  }
  printf("보너스 번호:%d ", *(Match_LOTTO + LOTTO_RESULT_SIZE - 1));
  printf("번호 일치:%d ", count);
  if (count == 6)
  {
   printf("등수 1등\n");
  }
  else if (count == 5)
  {
   if (bonus_count == 1)
   {
    printf("등수2등\n");
   }
   else
   {
    printf("등수3등\n");
   }
  }
  else if (count == 4)
  {
   printf("등수4등\n");
  }
  else if (count == 3)
  {
   printf("등수5등\n");
  }
  else
  {
   printf("등수에 없습니다. \n");
  }
  count = 0;
  bonus_count = 0;
 }

}

 

'언어' 카테고리의 다른 글

naver 지식인 - 1 (2015/ 08/ 30)  (0) 2015.08.30
2015_08_27  (0) 2015.08.27
swap  (0) 2015.08.27
linkedlist_a + linkedlist_b  (0) 2015.08.25
linkedlist _ 오름차순 정렬  (0) 2015.08.25