Array_03 경우의 수 출력하기

두 사람이 식사를 하기 위해서 어느 식당에 들렸다. 두 사람이 식사를 위해서 사용할 수 있는 금액의 한도는 9,000원이고, 한 사람당 하나의 메뉴만 주문하기로 했다. 이 식당의 메뉴와 가격이 아래의 표와 같을 때 두사람이 주문할 수 있는 모든 경우의 수를 출력하는 프로그램을 작성하시오.





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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <Windows.h>
 
char menuch1[6][7= { "ººÀ½¹ä" ,"ÅÁ¼öÀ°" ,"ÀÚÀå¸é" , "«»Í" , "«¥¸é" ,"¿Õ¸¸µÎ" };
 
char menuch2[2][7];
 
void check(int temp1 , int temp2) {
 
    int i,j;
 
    int count = temp1;
    for (i = 0; i < 2; i++) {
 
        for (j = 0; j < sizeof(menuch1[count]) / sizeof(char); j++) {
            menuch2[0][j] = menuch1[count][j];
        }
        count = temp2;
    }
}
 
int main(void){
     
    // ÇÑ»ç¶÷ÀÌ ÇѸ޴º¸¸ ¸ÔÀ½
    int menu[] = { 5000,10000,4000,4000,7000,4500 };
 
    //¹è¿­ ¼±¾ð
    int people[] = { 0,};
 
    int money = 9000;
    int i, j;
    int sum = 0;
    int count = 1;
 
    for (i = 0; i < sizeof(menu)/sizeof(int); i++) {
        for (j = i; j < 6; j++) {
 
            people[0= menu[i];
            people[1= menu[j];
 
            sum = people[0+ people[1];
 
            if (sum <= money) {
 
                check(i, j);
 
                printf("%d ¹ø ¹æ¹ý : %d(%s)¿Í %d(%s)\n", count, menu[i], menuch2[0],menu[j], menuch2[1]);
                count++;
 
            }
        }
    }
 
    system("pause");
    return 0;
}
cs

댓글