C++ 프로그래밍 질문있습니다ㅠ
#include
using namespace std;
int num;
int A[10000];
int B[10000];
int C[10000];
int value[10000];
int csg(int num1, int num2, int *array);
int main()
{
int N;
int D;
int n=0;
int M[10000];
int m=0;
int set[10000];
int *q;
int s;
q=&s;
while(1)
{
cin >> N;
if(N==-1)
return 0;
else if(N==0)
{
cout << "Please enter valid value. " << endl;
break;
}
else
{
while(1)
{
cin >> N;
if(N==-1)
return 0;
else if(N==0)
{
cout << "Please enter valid value. " << endl;
break;
}
else
{
while(1)
{
cin >> A[num];
cin >> B[num];
if((A[num]==0)&&(B[num]==0))
break;
num+=1;
}
}
for(int i=0; i<=num-1; i++)
{
if(A[i] < A[i+1])
break;
}
D=0;
n=csg(0, num, value);
for(int i=0; i<*q; i++)
{
n = value[i];
if(n == N)
{
D += 1;
for(int row=0; row<=num; row++)
{
cout << C[row] << " ";
M[D]+=C[row];
}
//these lines are used to make represented M be smallest value
if(D == 1)
m = M[D];
else
{
if(M[D] < m)
m = M[D];
}
}
if (m != 0)
cout << "# " << m << endl;
//If there isn't corresponding number n, I want to show you that there is no solution.
else if (m == 0)
cout << "# No solution found." << endl;
}
}
return 0;
}
int csg(int num1, int num2, int *array)
{
int q;
for(int i=0;i<=B[num1];i++)
{
C[num1]=i;
value[q]+=A[num1]*C[num1];
if(num1==num2)
{
q+=1;
}
else
{
num1+=1;
csg(num1, num2, value);
}
}
}
하고 컴파일 후에 실행해보았습니다.
값들을 입력하고 아웃풋을 봤는데 segmentation fault 라고 뜨네요ㅠㅠ
어떻게 해야할까요
그럴 경우에는 디버거를 써야 합니다. 디버거를
그럴 경우에는 디버거를 써야 합니다. 디버거를 사용하는 법을 알아보세요.
그러면 어느 위치에 문제가 있는지 찾을 수 있습니다.
그리고 질문하실때 어떤 플랫폼에서 (윈도우 리눅스 등) 어떤 컴파일러로
작업하는지 등등의 앞뒤 설명을 붙여야 도움을 받기가 쉽습니다.
음... 세그멘테이션 오류는 메모리 영역을 침범할때
음...
세그멘테이션 오류는 메모리 영역을 침범할때 주로 일어납니다. 변수들을 잘 살펴보세요.
피할 수 있을때 즐겨라! http://melotopia.net/b
댓글 달기