Devlog
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
using namespace std;

void lottoGen(int lotto[]);
int computeSum(const int lotto[]);
int oddEven(const int lotto[]);

int main() {
 int lotto[6];
 int count = 0, find, num, sum, odd;

 srand((unsigned int)time(NULL));

 while(count<10) {
   lottoGen(lotto);

   sum = computeSum(lotto);
   odd = oddEven(lotto);

   if (sum >= 81 && sum <= 200 && odd!=0) {
    sort(lotto, lotto + 6);

    for (int k = 0; k < 6; k++) {
     printf("%2d ", lotto[k]);
    }
    printf(" : %d [%d : %d]\n", sum, odd, 6-odd);
    
    count++;
   }
   
  }
 return 0;
}

void lottoGen(int lotto[]) {
 int num, find, count;
  lotto[0] = rand() % 45 + 1;
  count = 1;
  while(count < 6){
   num = rand() % 45 + 1;
   find = 0;
   for (int j = 0; j < count; j++) {
    if (num == lotto[j])
     find = 1;
    break;
   }
   if (find == 0) { //!find
    lotto[count] = num;
    count++;
   }
  }
 }

int computeSum(const int lotto[]) {
 int sum = 0;

 for (int i = 0; i < lotto[i]; i++)
  sum += lotto[i];

 return sum;
}

int oddEven(const int lotto[]) {
 int odd = 0;
 int a, b;
 for (int i = 0; i < 6; i++) {
  if (lotto[i] % 2 == 1)
   odd++;
 }
 if (odd >= 2 && odd <= 4) // 홀수가 2, 3, 4
  return odd;
 else
  return 0;
}
profile

Devlog

@덩이

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

검색 태그