Hsue66 / Algo

0 stars 0 forks source link

Table #7

Open Hsue66 opened 5 years ago

Hsue66 commented 5 years ago

include

using namespace std;

define MAXR 99

define MAXC 26

struct Elem { int val; int op; int start[2]; int finish[2]; };

Elem MAP[MAXR][MAXC]; int r, c; int checked[MAXR][MAXC];

void init(int C, int R) { r = R, c = C; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) MAP[i][j].op = MAP[i][j].val = 0; } }

int stoi(char str) { int idx, num; idx = num = 0; int flag = 1; if (!('0'<=str[idx] && str[idx] <= '9')) { if(str[idx] == '-') flag = -1; idx++; } do { num = num 10 + (str[idx] - '0'); } while (str[++idx]); return num * flag; }

void divide(char input[],char left, char right) { int flag = 0; for (int i = 0; input; input++, i++) { if (input == ',') { flag = 1; continue; } if (3 < i && flag == 0) left++ = input; if(flag == 1 && input != ')') right++ = input; } right = left = '\0'; }

void set(int col, int row, char input[]) { int i = row - 1; int j = col - 1; if (input[0] <= '9' || input[0] == '-') // 숫자일 경우 MAP[i][j].val = stoi(input); else { MAP[i][j].op = 1; char left[4], right[4]; divide(input, left, right); MAP[i][j].start[1] = left[0] - 'A'; MAP[i][j].start[0] = stoi(left); MAP[i][j].finish[1] = right[0] - 'A'; MAP[i][j].finish[0] = stoi(right); switch (input[2]) { case 'D': MAP[i][j].val = 0; break; case 'B': MAP[i][j].val = 1; break; case 'L': MAP[i][j].val = 2; break; case 'V': MAP[i][j].val = 3; break; case 'X': MAP[i][j].val = 4; break; case 'N': MAP[i][j].val = 5; break; case 'M': MAP[i][j].val = 6; break; default: break; } } }

int calc(int i, int j) { int op = MAP[i][j].val; if (op == 0); }

void update(int value[MAXR][MAXC]) { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) checked[i][j] = 0; } for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { if (checked[i][j] == 0) { checked[i][j] = 1; if (MAP[i][j].op == 0) value[i][j] = MAP[i][j].val; else {

            }
        }
    }
}

}

void test() { int R, C; R= C = 5; init(R,C);

set(3, 2, (char*)"5");
set(5, 2, (char*)"13");
set(1, 5, (char*)"2");
set(2, 1, (char*)"6");
set(1, 1, (char*)"-9");
set(3, 4, (char*)"9");
set(2, 2, (char*)"3");
set(2, 4, (char*)"7");
set(5, 3, (char*)"2");
set(3, 1, (char*)"5");
set(3, 4, (char*)"-9");
set(1, 2, (char*)"SUM(A5,E5)");
set(4, 2, (char*)"8");
set(4, 5, (char*)"MUL(E2,E3)");
set(2, 2, (char*)"SUB(E4,B4)");
set(1, 4, (char*)"-9");
set(1, 5, (char*)"ADD(C2,A4)");
for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++)
        cout << MAP[i][j].val << " ";
    cout << endl;
}

}