Advertisement
MUstar

IoT C언어 0627 - 로또자동추첨프로그램v1

Jun 28th, 2017
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. int menu(void);
  7. int lotto(int *cnt);
  8. int numlist(int *cnt);
  9. int numgraph(int *cnt);
  10. int rdnum_p(int *lotto_num);
  11. int graph_p(int *g_num);
  12. int pause(int err);
  13. int end(void);
  14.  
  15. struct lotto_db{int n1;int n2;int n3;int n4;int n5;int n6;};
  16. struct lotto_db table[1000]; //숫자값을 지우면 무제한...은 가능하나 Warning. 헌데 1000까지 갈련지는...
  17.  
  18. int main(void)
  19. {
  20.     menu();
  21.     end();
  22. }
  23.  
  24. int menu(void)
  25. {
  26.     srand((unsigned long)time(NULL));
  27.     int cnt=0, sele;
  28.     while(1)
  29.     {
  30.         system("clear");
  31.         printf("============로또자동추첨프로그램v1============\n");
  32.         printf("1)추첨 2)회차별_번호확인 3)번호확률현황 4)종료\n");
  33.         printf("==============================================\n");
  34.         printf(">");
  35.         scanf("%d", &sele);
  36.         if(sele==1) lotto(&cnt);
  37.         else if(sele==2) numlist(&cnt);
  38.         else if(sele==3) numgraph(&cnt);
  39.         else if(sele==4) break;
  40.         else pause(1);
  41.     }
  42. }
  43.  
  44. int lotto(int *cnt)
  45. {
  46.     system("clear");
  47.     int lotto_num[6];
  48.     if(*cnt==1000) printf("더이상 조회가 안되요.\n");
  49.     else
  50.     {
  51.     rdnum_p(lotto_num);
  52.             table[*cnt].n1 = lotto_num[0];
  53.             table[*cnt].n2 = lotto_num[1];
  54.             table[*cnt].n3 = lotto_num[2];
  55.             table[*cnt].n4 = lotto_num[3];
  56.             table[*cnt].n5 = lotto_num[4];
  57.             table[*cnt].n6 = lotto_num[5];
  58.         printf("로또번호가 생성되었습니다. 추가생성가능한 횟수는 %d회입니다.\n", 999-*cnt);
  59.         printf("|%d|%d|%d|%d|%d|%d|\n", table[*cnt].n1,table[*cnt].n2,table[*cnt].n3,table[*cnt].n4,table[*cnt].n5,table[*cnt].n6);
  60.         *cnt+=1;
  61.     }
  62.     pause(0);
  63. }
  64. int numlist(int *cnt)
  65. {
  66.     system("clear");
  67.     if(*cnt==0) pause(4);
  68.     else
  69.     {
  70.         printf("현재까지 생성한 로또번호는 아래와 같습니다.\n");
  71.         printf("------------------------\n");
  72.         for(int c_cnt=0; c_cnt<*cnt; c_cnt++)
  73.         {
  74.             if(c_cnt<9)printf("|000%d|",c_cnt+1);
  75.             else if(c_cnt<99) printf("|00%d|",c_cnt+1);
  76.             else if(c_cnt<999) printf("|0%d|",c_cnt+1);
  77.             else printf("|%d|",c_cnt+1);
  78.             printf("%d/%d/%d/%d/%d/%d\n",table[c_cnt].n1,table[c_cnt].n2,table[c_cnt].n3,table[c_cnt].n4,table[c_cnt].n5,table[c_cnt].n6);
  79.         }
  80.         printf("------------------------\n");
  81.         pause(0);
  82.     }
  83. }
  84. int numgraph(int *cnt)
  85. {
  86.     system("clear");
  87.     int temp_num=0,g_num[45];
  88.     for(int g_clr=0;g_clr<45;g_clr++) //g_num 숫자클리어
  89.     {
  90.         g_num[g_clr] = 0;
  91.     }
  92.     if(*cnt==0) pause(4);
  93.     else
  94.     {
  95.         for(int g_cnt=0;g_cnt<*cnt;g_cnt++)
  96.         {
  97.             temp_num = table[g_cnt].n1;
  98.                 g_num[temp_num-1]+=1;
  99.             temp_num = table[g_cnt].n2;
  100.                 g_num[temp_num-1]+=1;
  101.             temp_num = table[g_cnt].n3;
  102.                 g_num[temp_num-1]+=1;
  103.             temp_num = table[g_cnt].n4;
  104.                 g_num[temp_num-1]+=1;
  105.             temp_num = table[g_cnt].n5;
  106.                 g_num[temp_num-1]+=1;
  107.             temp_num = table[g_cnt].n6;
  108.                 g_num[temp_num-1]+=1;
  109.         }
  110.         printf("한번도 출력되지 않는 숫자는 그래프에서 제외됩니다. :)\n");
  111.         printf("-------\n");
  112.         graph_p(g_num);
  113.     }
  114.     pause(0);
  115. }
  116.  
  117. int rdnum_p(int *lotto_num)
  118. {  
  119.     int p_cnt=0, ec_cnt=0;
  120.     int temp_num ;
  121.     while(p_cnt<6)
  122.     {
  123.         int cksum=0;
  124.         //숫자를 골고루 섞자. 누가 랜덤을 돌린 두번째번호가 45이라고하는 끔직한 생각을 했느냐.
  125.         /*if (p_cnt==5)temp_num = (rand()%44)+1;
  126.         else if (p_cnt==4)temp_num = (rand()%43)+1;
  127.         else if (p_cnt==3)temp_num = (rand()%42)+1;
  128.         else if (p_cnt==2)temp_num = (rand()%41)+1;
  129.         else if (p_cnt==1)temp_num = (rand()%39)+1;
  130.         else temp_num = (rand()%19)+1;
  131.         */
  132.         //printf("%d//뛰어쓰기나나\n",temp_num);
  133.        
  134.         temp_num = (rand()%45)+1;
  135.         for(int r_cnt=0;r_cnt<p_cnt;r_cnt++)
  136.         {
  137.             if(lotto_num[r_cnt]==temp_num) cksum=1;
  138.             else if(temp_num<lotto_num[p_cnt-1]) cksum=2;
  139.             else if(temp_num>45) cksum=3;
  140.             else cksum = 0;
  141.         }
  142.         if (cksum==0)
  143.         {
  144.             lotto_num[p_cnt] = temp_num;
  145.             p_cnt++;
  146.         }
  147.         ec_cnt++;
  148.         if(ec_cnt==100){ec_cnt=0; p_cnt=0;} //Stop Endless Circulation.
  149.     }
  150. }
  151.  
  152. int graph_p(int *g_num)
  153. {
  154.     for(int p_cnt=0;p_cnt<45;p_cnt++)
  155.     {
  156.         if(g_num[p_cnt]>0)
  157.         {
  158.             if(p_cnt<9)printf("|0%d",p_cnt+1);
  159.                 else printf("|%d",p_cnt+1);
  160.             if(g_num[p_cnt]<10)printf("|00%d|",g_num[p_cnt]);
  161.                 else if(g_num[p_cnt]<100)printf("|0%d|",g_num[p_cnt]);
  162.                 else printf("|%d|",g_num[p_cnt]);
  163.             for(int pp=0;pp<g_num[p_cnt];pp++)
  164.             {
  165.                 printf("■");
  166.             }
  167.             printf("|\n");
  168.         }
  169.     }
  170. }
  171.  
  172. int pause(int err)
  173. {
  174.     char p_dummy[100];
  175.     if(err==1){system("clear"); printf("잘못된 값을 입력했습니다.");}
  176.     if(err==2){system("clear"); printf("같은값을 찾을수가 없습니다.");}
  177.     if(err==3){system("clear"); printf("삭제되었습니다.\n");}
  178.     if(err==4){system("clear"); printf("DB에 아무련번호가 없어요. 만들어주세요.\n");}
  179.     if(err==5){system("clear"); printf("미구현\n");}
  180.     printf("\n-------");
  181.     printf("\n계속하실려면 아무글자나 입력후 엔터를 눌려주세요.\n");
  182.     scanf("%s", p_dummy);
  183.     strcpy(p_dummy, " ");
  184. }
  185.  
  186. int end(void)
  187. {
  188.     system("clear");
  189.     printf("프로그램을 종료합니다.\n");
  190.     return 0;
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement