여기서 오류가 뭘까요
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stack>
#include <math.h>
int a = 0, b = 0, c = 0;
int cnt = 1;
int flag = 1;
using namespace std;
int find(stack<int> s) {
int current = 0;
while (!s.empty()) {
current = current ^ (s.top() * cnt);
s.pop();
cnt++;
}
if (flag == 0) {
return current * (-1);
} else {
return current;
}
}
int main() {
char arr[100] = {0};
scanf("%s", arr);
int cnt = strlen(arr);
stack<int> s;
for (int j = 0; j < cnt; j++) {
if (arr[j] >= '0' && arr[j] <= '9') {
s.push(arr[j] - '0');
} else if (arr[j] == 'x') {
if (arr[j - 1] == '-') {
a = -1;
} else if (arr[j - 1] == '+') {
a = 1;
}
if (arr[j + 1] == '^') {
if (!s.empty()) {
if (arr[0] == '-') {
flag = 0;
}
a = find(s);
}
j++;
if (arr[j + 2] == '+') {
b = find(s);
} else {
flag = 0;
b = find(s);
}
}
}
}
if (!s.empty()) {
c = find(s);
}
int D = (b * b) - (4 * a * c);
if (D < 0) {
printf("x = (%d + sqrt(%d)i) / %d or x = (%d - sqrt(%d)i) / %d or x = %d\n", -b, abs(D), a * 2, -b, abs(D), a * 2, -b/(2*a));
} else if (D > 0) {
printf("x = (%d + sqrt(%d)) / %d or x = (%d - sqrt(%d)) / %d or x = %d\n", -b, D, a * 2, -b, D, a * 2, (-b + sqrt(D)) / (2 * a));
} else {
printf("x = %d / %d\n", -b, a * 2);
}
return 0;
}
불러오는 중...