고급 C언어 문제 입니다 한번만 도와주십시오

jch8854의 이미지

1 부터 6까지 숫자를 이용하여, 연결된 선으로 더했을때 합이 9 / 10/ 11/ 12 가되는 알고리즘 (for문 이용)

Total Solution Set

9 4,2,3 5,3,1 6,1,2
9 4,3,2 6,2,1 5,1,3
10 2,3,5 4,5,1 6,1,3
10 2,5,3 6,3,1 4,1,5
11 1,4,6 3,6,2 5,2,4
11 1,6,4 5,4,2 3,2,6
12 1,5,6 2,6,4 3,4,5
12 1,6,5 3,5,4 2,4,6

위와 같이 출력되게 하라는데 도저히 규칙을 못찾아서 for문을 못돌리겠습니다.. 규칙을 찾아서 뭘 돌리든 하죠...

제발 도와주십시요 ㅠㅠ

bbaijang의 이미지

일단은 1~6까지의 숫자에서 세개를 뽑아 더하는 합이 9가되는 숫자 조합을 출력하면 다음과 같습니다.
(1,2,6) (1,3,5) (2,4,3) 대충 위의 결과값 첫번째와 비슷하죠???

9 4,2,3 5,3,1 6,1,2

그래서 간단히 N을 이루는 조합 문제이면 간단한데...

두번째 결과값과... 결과 출력의 순서를 고민한다면...
9 4,3,2 6,2,1 5,1,3

저도 잘 모르겠네요... 도움이 안되서 죄송합니다.
교수님께 해당 문제에 대한 규칙이 어떤것인지 다시 물어보심이 좋을 것 같습니다.

아무리봐도 조합 출력 문제인 것 같은데... 도저히 규칙성을 찾기가 힘드네요.

익명 사용자의 이미지

#include
main()
{
int in_num=9;
int arr[3][3]={0,0,0,0,0,0,0,0,0};
int a,b,c,r;
int k;
printf("Total Solution Set\n\n");
for(in_num=9; in_num<=12; ++in_num){
k=2;
for(a=1; a<=6; ++a)
for(b=1; b<=6; ++b)
for(c=1; c<=6; ++c)
for(r=1; r<=6; ++r){
if(a+b+c==in_num && in_num-(r+c)>0 && in_num-(r+c)<=6 && in_num-(r+b)>0 && in_num-(r+b)<=6)
{
arr[0][0]=a; arr[0][1]=b; arr[0][2]=c;
arr[1][0]=in_num-(r+c); arr[1][1]=c; arr[1][2]=r;
arr[2][0]=in_num-(r+b); arr[2][1]=r; arr[2][2]=b;
if(a!=b && b!=c&& a!=c && c!=r && in_num-(r+c) != r && in_num-(r+b)!=r && in_num-(r+b)!=b && in_num-(r+c)!=c)
{
if(!(arr[1][0]==b && arr[1][1]==c && arr[1][2]==a) )
if(!(arr[1][0]==b && arr[1][1]==a && arr[1][2]==c ))
if(!(arr[1][0]==c && arr[1][1]==b && arr[1][2]==a ))
if(!(arr[1][0]==c && arr[1][1]==a && arr[1][2]==b ))
if(!(arr[1][0]==a && arr[1][1]==b && arr[1][2]==c ))
if(!(arr[1][0]==a && arr[1][1]==c && arr[1][2]==b ))
if(k>0)
{
printf("%d %d,%d,%d ",in_num, arr[0][0], arr[0][1], arr[0][2]);
printf("%d,%d,%d ", arr[1][0], arr[1][1], arr[1][2]);
printf("%d,%d,%d\n", arr[2][0], arr[2][1], arr[2][2]);
k--;
}
}
}
}
}


printf("end");
getchar();
}

익명 사용자의 이미지

#include <stdio.h>
main()
{
	int in_num=9;
	int arr[3][3]={0,0,0,0,0,0,0,0,0};
	int a,b,c,r;
	int k=0,p;
	int temp[3][3]={0,0,0,0,0,0,0,0,0};
	printf("Total Solution Set\n\n");
	for(in_num=9; in_num<=12; ++in_num){
	k=2;
	for(a=1; a<=6; ++a)
		for(b=1; b<=6; ++b)
			for(c=1; c<=6; ++c)
				for(r=1; r<=6; ++r){
					if(a+b+c==in_num &&a!=b && b!=c&& a!=c && c!=r&& in_num-(r+c)>0 && in_num-(r+c)<=6  && in_num-(r+b)>0 && in_num-(r+b)<=6)
					{
						arr[0][0]=a;			arr[0][1]=b;			arr[0][2]=c;
						arr[1][0]=in_num-(r+c); arr[1][1]=c;			arr[1][2]=r; 
						arr[2][0]=in_num-(r+b);	arr[2][1]=r;			arr[2][2]=b;
						if( in_num-(r+c) != r && in_num-(r+b)!=r && in_num-(r+b)!=b && in_num-(r+c)!=c)
						{
							if(!(arr[1][0]==b && arr[1][1]==c && arr[1][2]==a) )
							if(!(arr[1][0]==b && arr[1][1]==a && arr[1][2]==c ))
							if(!(arr[1][0]==c && arr[1][1]==b && arr[1][2]==a ))
							if(!(arr[1][0]==c && arr[1][1]==a && arr[1][2]==b ))
							if(!(arr[1][0]==a && arr[1][1]==b && arr[1][2]==c ))
							if(!(arr[1][0]==a && arr[1][1]==c && arr[1][2]==b ))
							if(k>0){
								printf("%d %d,%d,%d ",in_num, arr[0][0], arr[0][1], arr[0][2]);
								printf("%d,%d,%d ", arr[1][0], arr[1][1], arr[1][2]);
								printf("%d,%d,%d\n", arr[2][0], arr[2][1], arr[2][2]);
								k--;
							}
 
						}				
					}
				}
	}		
 
 
	printf("end");
	getchar();
}
익명 사용자의 이미지

도와주시네요....

숙제는 스스로....

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.