[해결] 배열 초기화
글쓴이: Silvester / 작성시간: 토, 2011/10/15 - 3:48오전
#include <stdio.h> #include <math.h> int main() { int n, i, q, c, sz, idx, idx2, t1, t2, elteres, ce = 0; int z, j, diff, times=0, l, m,r,o,b; scanf("%d",&n); // 총 횟수를 받아옵니다 for (z = 0; z < n; z ++) { scanf("%d %d",&q , &c); // q = 받아오는 개수 c = 원하는 숫자 int set[q]; // 초기화 int diff[l]; // 초기화 l = 0; sz = q; for (j = 0 ; j < q ; j++) { scanf("%d",&set[j]); //1렬로 나열된 데이터를 space로 구분해서 받음. } for(idx = 0; idx < sz; idx++) { for(idx2 = idx + 1; idx2 < sz; idx2++) { if( idx < idx2 ) { diff[l] += abs(set[idx] + set[idx2] - c); // 절대값으로 차이를 알아보자. t1 = set[idx]; t2 = set[idx2]; l += 1; //무조건 추가. } } m = l; } for (l=0; l<m; l++){ printf("diffrenece : %d \n", diff[l]); // 메모리 덤프 확인용 (디버깅용) } for (r=0; r<c; r++) { for (o=0 ; o<m ; o++) { if(diff[o] == r) ++times; // 있으면 있는만큼 추가 } if (times > 0) break; //가까운 숫자들 집합 횟수를 셌으므로 끝. } printf("%d \n" ,times); } return 0; }
두수의 합의 집합 중 주어진 수와 가장 가까운 집합을 구하는 과정입니다.
루프하면 배열의 데이터들이 덤프되고 새 데이터를 가져와야하는데 그렇지 못합니다. 왜그렇죠;;
C 뉴비라서 하나도 모르겠습니다.
Forums:
일단..
뉴비시라니깐 말씀드릴게요..
다른사람과 커뮤니케이션하실때 , 용어를 가능하면 명확한걸 써주셔야합니다.
'덤프' 라는 단어는 이럴때 사용하는게 아니에요.. 회사에서 사용하는 공식문서에서는 맨 앞부분에 그 문서에서 사용하는 단어들에 대해서 따로 정의된 내용을 포함하기도하죠.. 그만큼 용어가 중요한데 , 님이 이렇게 단어를 사용하시면 님에게 배우는사람도 그렇고 님 주변사람도 그렇고 대화하기 힘듭니다.
저건 그냥 배열이 printf 문으로 출력이안되요 .. 정도의 질문이면 되는거구요.
그리고 코드에 문제가 많은데요..
1.님의 의도대로 하려면 int *set; set = (int*)malloc(sizeof(int)*q); 이런식으로 해줘야합니다.
그외에도 코드에 이상한부분이 많네요.. C언어 300제 한번 정도 보시고 그때도 해결안되면 다시 질문해주세요.
..덤프라는 용어를...
이런식으로도 쓰는군요.......하하하하...재밌네요;
댓글 달기