자료구조 다항식 문제 입니다.

KimSuMin Reply 7 years 26 weeks ago
//YOUR_CODE polynomial poly_arithmetic(polynomial P1, polynomial P2, int op) { //다항식 덧셈 if (op == 0) { polynomial P3_ADD; int P1_pos = 0, P2_pos = 0, P3_pos = 0; int degree_P1 = P1.degree; int degree_P2 = P2.degree; P3_ADD.degree = MAX(P1.degree, P2.degree); while (P1_pos <= P1.degree&&P2_pos <= P2.degree) { if (degree_P1 > degree_P2) { P3_ADD.coef[P3_pos++] = P1.coef[P1_pos++]; degree_P1--; } else if (degree_P1 == degree_P2) { P3_ADD.coef[P3_pos++] = P1.coef[P1_pos++] + P2.coef[P2_pos++]; degree_P1--; degree_P2--; } else { P3_ADD.coef[P3_pos++] = P2.coef[P2_pos++]; degree_P2--; } } return P3_ADD; } //다항식 뺄셈 if (op == 1) { polynomial P3_SUB; int P1_pos = 0, P2_pos = 0, P3_pos = 0; int degree_P1 = P1.degree; int degree_P2 = P2.degree; P3_SUB.degree = MAX(P1.degree, P2.degree); while (P1_pos <= P1.degree&&P2_pos <= P2.degree) { if (degree_P1 > degree_P2) { P3_SUB.coef[P3_pos++] = P1.coef[P1_pos++]; degree_P1--; } else if (degree_P1 == degree_P2) { P3_SUB.coef[P3_pos++] = P1.coef[P1_pos++] - P2.coef[P2_pos++]; degree_P1--; degree_P2--; } else if (degree_P1 == 0) { P3_SUB.coef[P3_pos++] = -P2.coef[P2_pos++]; degree_P2--; } else { P3_SUB.coef[P3_pos++] = P2.coef[P2_pos++]; degree_P2--; } } return P3_SUB; } //다항식 곱셈 if (op == 2) { polynomial P3_MUL; int i, j, k; int P1_pos = 0, P2_pos = 0, P3_pos = 0; int degree_p1 = P1.degree; int degree_p2 = P2.degree; P3_MUL.degree = P1.degree + P2.degree; for (i = 0; i <= P3_MUL.degree; i++) { P3_MUL.coef[i] = 0; } for (i = 0; i <= degree_p1; i++) { for (j = 0; j <= degree_p2; j++) { for (k = 0; k <= P3_MUL.degree; k++) { if ((i + j) == k) P3_MUL.coef[k] += P1.coef[i] * P2.coef[j]; } } } return P3_MUL; } } polynomial poly_print(polynomial p) { int j; for ( j = 0; j < p.degree; j++) printf("%d ", p.coef[j]); if ( j = p.degree) printf("%d", p.coef[j]); printf("\n"); } 이렇게 했는데 제출했더니 틀렸다고 뜹니다,! 어디서 틀렸는지 알려주세용
withcs1 Reply 7 years 26 weeks ago
0 0 1 1 1 의 경우 -1 -1 이 출력되야합니당
KimSuMin Reply 7 years 26 weeks ago
0 0 1 1 1 했을때 1 1 -1 -1 0 0 이렇게 출력되는데 어디가 잘못된거죠ㅜ
withcs1 Reply 7 years 26 weeks ago
0 0의 경우엔 0을 출력하셔야 합니당