#์ˆ˜ํ•™ #์ฝ”๋”ฉ

์ฝ”๋”ฉ : ์—ฌ๋Ÿฌ ๋ฌธ์ž์—ด์—์„œ ๋ฌธ์ž์˜ ๊ฐœ์ˆ˜ ๋ถ„์„

applemint612 2020. 1. 25. 19:40

Q) ๊ณก์€ ์ด 9ํŒ€์ด ์žˆ๊ณ , ํŒ€๋งˆ๋‹ค ์ผ์ • ์ธ์›์˜ ๋ฉค๋ฒ„๊ฐ€ ์žˆ๋Š”๋ฐ ์™ธ๋ถ€๊ณต์—ฐ์— ๋”ฑ ์ˆซ์ž๋ฅผ ๋งž์ถฐ ์ธ์›์„ ๋ณด๋‚ด์•ผํ–ˆ๊ธฐ์—, ์–ด๋–ค ํŒ€์„ ๋ณด๋‚ด์•ผ ์ˆซ์ž๊ฐ€ ๋”ฑ ๋งž๋Š”์ง€ ์•Œ์•„๋ด์•ผํ•œ๋‹ค.

๊ทธ๋Ÿฌ๋‚˜ ํŒ€๋งˆ๋‹ค ๋ฉค๋ฒ„๊ฐ€ ๊ฒน์น˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์•„ ํ•˜๋‚˜ํ•˜๋‚˜ ์†์œผ๋กœ ๋”ฐ์ ธ๊ฐ€๊ธฐ๋ณด๋‹ค๋Š” ์ฝ”๋”ฉ์ด ํŽธํ•  ๊ฒƒ ๊ฐ™์•„ ์ฝ”๋”ฉํ•ด๋ดค๋‹ค.

์ฝ”๋“œ๋Š” ๋Œ€๋žต 300์ค„ ์ •๋„ ๋‚˜์˜จ๋‹ค.

๋จผ์ € ์‚ฌ๋žŒ๋งˆ๋‹ค ์ผ์ •ํ•œ ์ฝ”๋“œ'a~e, A~Z๊นŒ์ง€ ์ด 31๊ฐœ'๋ฅผ ๋ถ€์—ฌํ•œ ํ›„, ํŒ€๋งˆ๋‹ค ๋ฉค๋ฒ„๋ฅผ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•ด ์ •๋ฆฌํ•ด๋ณด์•˜๋‹ค.

Team 1 ๋ค๋ฆฌํ‹ฐ (4๋ช…) EPMT

Team 2 ์ €์ ˆ (9๋ช…) ABEFINOPM 

Team 3 ๋ผ์ด์–ธ (6๋ช…) DGNQUV

Team 4 ํž™ (4๋ช…) FLNQ 

Team 5 ์ด๋ฃจ๋ฆฌ (10๋ช…) GPRSQMWXYV 

Team 6 ํ”Œ๋ผ์›Œ์ƒค์›Œ (10๋ช…) EGHNOUZWXV

Team 7 ์žํ•‘ (7๋ช…) ACEHJZT 

Team 8 blue flame (8๋ช…) KPQabcVZ 

Team 9 ์˜ต์„ธ์…˜ (7๋ช…) CJLdeaZ

์ดํ›„, strcpy์™€ strcatํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด ๋ฉค๋ฒ„๋ฅผ ํ•œ ๋ฌธ์ž์—ด๋กœ ๋ฌถ์€ ํ›„ ๊ฒน์น˜๋Š” ๋ฌธ์ž๋ฅผ ๋นผ๋ฒ„๋ฆฌ๋ฉด ๋œ๋‹ค.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
strcpy(temp, acting[a]);
strcat(temp, acting[b]);
strcat(temp, acting[c]);
leng_before = strlen(temp);
for (i = 0; i < leng_before; i++)
    {
        for (j = i + 1; j < leng_before; j++)
        {
            if (temp[i] == temp[j])
            {
                for (k = j; k < leng_before; k++)
                {
                    temp[k] = temp[k + 1];
                }
            }
        }
    }
    leng_after = strlen(temp);
    if (leng_after <= 20)
    {
        printf("%s %d\n", temp, leng_after);
    }
cs

์ด๋Ÿฐ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด (๊ฒน์น˜๋Š” ๊ณก์—์„œ ํ•œ ๋ช…์œผ๋กœ ์„ธ์–ด์ง€๋Š”) ๋ฉค๋ฒ„์™€ ์ „์ฒด ๋ฉค๋ฒ„ ์ˆซ์ž๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ธฐ๋Šฅ A์™€ B๋ฅผ ๋„์ž…ํ•˜์˜€๋Š”๋ฐ ๊ธฐ๋Šฅ A๋Š” Team์˜ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด(ex. Team 1, Team 2, Team 3) ๊ฐ Team ๋งˆ๋‹ค ๊ฒน์น˜๋Š” ๋ฉค๋ฒ„๋ฅผ ๊ณ ๋ คํ•ด ์ด ๋ฉค๋ฒ„์˜ ์ˆซ์ž๋ฅผ ๊ตฌํ•ด์ค€๋‹ค.

๊ธฐ๋Šฅ B๋Š” ๊ฐˆ ์ˆ˜ ์žˆ๋Š” Team์˜ ์ˆ˜์™€ ์ธ์›์˜ ์ƒํ•œ์น˜๋ฅผ ์ž…๋ ฅํ•˜๋ฉด(ex. 4ํŒ€์ด ๊ฐˆ ์ˆ˜ ์žˆ๊ณ  ์ด 17๋ช…์ดํ•˜๊ฐ€ ๊ฐ€์•ผํ•จ) ๊ฐ€๋Šฅํ•œ Team์˜ ์กฐํ•ฉ์„ ๋ชจ๋‘ ๋ณด์—ฌ์ค€๋‹ค.

๊ธฐ์ˆ˜๋ณ„๋กœ ๋ฌธ์ž๋“ค์„ ์žฌ์กฐํ•ฉํ•ด ๋‹ค์‹œ ๋ณด์—ฌ์ฃผ๋Š” ๊ธฐ๋Šฅ๋„ ์ถ”๊ฐ€ํ–ˆ๋‹ค

์ฝ”๋”ฉ ์™„์„ฑ๋ณธ
๋””๋ฒ„๊น…ํ–ˆ์„ ๋•Œ ๊ฒฐ๊ณผ

์ฝ”๋“œ๋Š” '๋”๋ณด๊ธฐ' ํด๋ฆญ

๋”๋ณด๊ธฐ

#define _CRT_SECURE_NO_WARNINGS
#include 
#include 


void main()
{
char acting[9][20] = {"EPMT", "ABEFINOPM", "DGNQUV", "FLNQ", "GPRSQMWXYV", "EGHNOUZWXV", "ACEHJZT", "KPQabcVZ", "CJLdeAZ"};

char temp[80];
char null[1] = {""};
int leng_before, leng_after;
int a, b, c, d, e, f, i, j, k;
char decide;
char tem;
int team, number;

printf("- Team 1 ๋ค๋ฆฌํ‹ฐ (4๋ช…) EPMT\n- Team 2 ์ €์ ˆ (9๋ช…) ABEFINOPM\n- Team 3 ๋ผ์ด์–ธ (6๋ช…) DGNQUV\n- Team 4 ํž™ (4๋ช…) FLNQ\n- Team 5 ์ด๋ฃจ๋ฆฌ (10๋ช…) GPRSQMWXYV\n- Team 6 ํ”Œ๋ผ์›Œ์ƒค์›Œ (10๋ช…) EGHNOUZWXV\n- Team 7 ์žํ•‘ (7๋ช…) ACEHJZT\n- Team 8 blue flame (8๋ช…) KPQabcVZ\n- Team 9 ์˜ต์„ธ์…˜ (7๋ช…) CJLdeAZ\n\n");

printf("๊ธฐ๋Šฅ A : ํŒ€์„ ์ž…๋ ฅํ•˜๋ฉด ์ธ์›์„ ์•Œ๋ ค์คŒ\n๊ธฐ๋Šฅ B : ์ธ์›์„ ์ž…๋ ฅํ•˜๋ฉด ํŒ€์„ ์•Œ๋ ค์คŒ\n\n");
printf("-----------------------\n\n");

while (1)
{
scanf("%c", &decide);

if (decide == 'A')
{
printf("- ํŒ€์„ ์ž…๋ ฅํ•˜๋ฉด ์ธ์›์„ ์•Œ๋ ค์คŒ\n- ํŒ€์„ ์ž…๋ ฅํ•˜์„ธ์š”\n- 0์„ ์ž…๋ ฅํ•˜๋ฉด ์ข…๋ฃŒ\n");

strcpy(temp, null);
while (1)
{
scanf("%d", &a);

if (a >= 1 && a <= 9)
{
strcat(temp, acting[a-1]);
}
else
break;
}
leng_before = strlen(temp);
for (i = 0; i < leng_before; i++)
{
for (j = i + 1; j < leng_before; j++)
{
if (temp[i] == temp[j])
{
for (k = j; k < leng_before; k++)
{
temp[k] = temp[k + 1];
}
}
}
}
leng_after = strlen(temp);

printf("\nํŒ€์› : %s , ํŒ€์› ์ˆซ์ž : %d\n", temp, leng_after);

for (i = 0; i < leng_after; i++)
{
for (j = i + 1; j < leng_after; j++)
{
if (temp[i] > temp[j])
{
tem = temp[i];
temp[i] = temp[j];
temp[j] = tem;
}
}
}
printf("๊ธฐ์ˆ˜๋ณ„๋กœ : %s\n\n", temp);
printf("-----------------------\n\n");
}

else if (decide == 'B')
{
printf("- ์ธ์›์„ ์ž…๋ ฅํ•˜๋ฉด ํŒ€์„ ์•Œ๋ ค์คŒ\n- nํŒ€์ด ๊ฐ€๋Š” ๊ฒฝ์šฐ n๋ช… ์ดํ•˜์˜ ๊ฒฝ์šฐ์˜ ์ˆ˜\n");
scanf("%d %d", &team, &number);

if (team == 3)
{
printf("<%dํŒ€์ด ๊ฐ€๋Š” ๊ฒฝ์šฐ %d๋ช…์ดํ•˜ ๊ฒฝ์šฐ์˜ ์ˆ˜> \n\n", 3, number);

for (a = 0; a <= 8; a++)
{
for (b = a + 1; b <= 8; b++)
{
for (c = b + 1; c <= 8; c++)
{
strcpy(temp, acting[a]);
strcat(temp, acting[b]);
strcat(temp, acting[c]);
leng_before = strlen(temp);
for (i = 0; i < leng_before; i++)
{
for (j = i + 1; j < leng_before; j++)
{
if (temp[i] == temp[j])
{
for (k = j; k < leng_before; k++)
{
temp[k] = temp[k + 1];
}
}
}
}
leng_after = strlen(temp);
if (leng_after <= number)
{
printf("ํŒ€์› : %s ๊ฐ€๋Š” ํŒ€ : %d %d %d ์ „์ฒด์ธ์› : %d\n", temp, a + 1, b + 1, c + 1, leng_after);
for (i = 0; i < leng_after; i++)
{
for (j = i + 1; j < leng_after; j++)
{
if (temp[i] > temp[j])
{
tem = temp[i];
temp[i] = temp[j];
temp[j] = tem;
}
}
}
printf("๊ธฐ์ˆ˜๋ณ„๋กœ : %s\n\n", temp);
}
}
}
}
}

else if (team == 4)
{
printf("<%dํŒ€์ด ๊ฐ€๋Š” ๊ฒฝ์šฐ %d๋ช…์ดํ•˜ ๊ฒฝ์šฐ์˜ ์ˆ˜> \n\n", 4, number);

for (a = 0; a <= 8; a++)
{
for (b = a + 1; b <= 8; b++)
{
for (c = b + 1; c <= 8; c++)
{
for (d = c + 1; d <= 8; d++)
{
strcpy(temp, acting[a]);
strcat(temp, acting[b]);
strcat(temp, acting[c]);
strcat(temp, acting[d]);
leng_before = strlen(temp);
for (i = 0; i < leng_before; i++)
{
for (j = i + 1; j < leng_before; j++)
{
if (temp[i] == temp[j])
{
for (k = j; k < leng_before; k++)
{
temp[k] = temp[k + 1];
}
}
}
}
leng_after = strlen(temp);
if (leng_after <= number)
{
printf("ํŒ€์› : %s ๊ฐ€๋Š” ํŒ€ : %d %d %d %d ์ „์ฒด์ธ์› : %d\n", temp, a + 1, b + 1, c + 1, d + 1, leng_after);
for (i = 0; i < leng_after; i++)
{
for (j = i + 1; j < leng_after; j++)
{
if (temp[i] > temp[j])
{
tem = temp[i];
temp[i] = temp[j];
temp[j] = tem;
}
}
}
printf("๊ธฐ์ˆ˜๋ณ„๋กœ : %s\n\n", temp);
}
}

}
}
}
}
else if (team == 5)
{
printf("<%dํŒ€์ด ๊ฐ€๋Š” ๊ฒฝ์šฐ %d๋ช…์ดํ•˜ ๊ฒฝ์šฐ์˜ ์ˆ˜> \n\n", 5, number);

for (a = 0; a <= 8; a++)
{
for (b = a + 1; b <= 8; b++)
{
for (c = b + 1; c <= 8; c++)
{
for (d = c + 1; d <= 8; d++)
{
for (e = d + 1; e <= 8; e++)
{
strcpy(temp, acting[a]);
strcat(temp, acting[b]);
strcat(temp, acting[c]);
strcat(temp, acting[d]);
strcat(temp, acting[e]);
leng_before = strlen(temp);
for (i = 0; i < leng_before; i++)
{
for (j = i + 1; j < leng_before; j++)
{
if (temp[i] == temp[j])
{
for (k = j; k < leng_before; k++)
{
temp[k] = temp[k + 1];
}
}
}
}
leng_after = strlen(temp);
if (leng_after <= number)
{
printf("ํŒ€์› : %s ๊ฐ€๋Š” ํŒ€ : %d %d %d %d %d ์ „์ฒด์ธ์› : %d\n", temp, a + 1, b + 1, c + 1, d + 1, e + 1, leng_after);
for (i = 0; i < leng_after; i++)
{
for (j = i + 1; j < leng_after; j++)
{
if (temp[i] > temp[j])
{
tem = temp[i];
temp[i] = temp[j];
temp[j] = tem;
}
}
}
printf("๊ธฐ์ˆ˜๋ณ„๋กœ : %s\n\n", temp);
}
}
}

}
}
}
}
else if (team == 6)
{
printf("<%dํŒ€์ด ๊ฐ€๋Š” ๊ฒฝ์šฐ %d๋ช…์ดํ•˜ ๊ฒฝ์šฐ์˜ ์ˆ˜> \n\n", 6, number);

for (a = 0; a <= 8; a++)
{
for (b = a + 1; b <= 8; b++)
{
for (c = b + 1; c <= 8; c++)
{
for (d = c + 1; d <= 8; d++)
{
for (e = d + 1; e <= 8; e++)
{
for (f = e + 1; f <= 8; f++)
{
strcpy(temp, acting[a]);
strcat(temp, acting[b]);
strcat(temp, acting[c]);
strcat(temp, acting[d]);
strcat(temp, acting[e]);
strcat(temp, acting[f]);
leng_before = strlen(temp);
for (i = 0; i < leng_before; i++)
{
for (j = i + 1; j < leng_before; j++)
{
if (temp[i] == temp[j])
{
for (k = j; k < leng_before; k++)
{
temp[k] = temp[k + 1];
}
}
}
}
leng_after = strlen(temp);
if (leng_after <= number)
{
printf("ํŒ€์› : %s ๊ฐ€๋Š” ํŒ€ : %d %d %d %d %d %d ์ „์ฒด์ธ์› : %d\n", temp, a + 1, b + 1, c + 1, d + 1, e + 1, f + 1, leng_after);
for (i = 0; i < leng_after; i++)
{
for (j = i + 1; j < leng_after; j++)
{
if (temp[i] > temp[j])
{
tem = temp[i];
temp[i] = temp[j];
temp[j] = tem;
}
}
}
printf("๊ธฐ์ˆ˜๋ณ„๋กœ : %s\n\n", temp);
}
}
}

}
}
}
}
}
printf("-----------------------\n\n");
}
}
}