Created
August 14, 2017 02:47
-
-
Save lstar2397/15866f5cc699053fa8de20dbc56dd835 to your computer and use it in GitHub Desktop.
성냥개비로 그린 수식: 하나만 대충 풀어본거
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <string.h> | |
| #include <stdlib.h> | |
| #include <stdio.h> | |
| int CTI(char c); | |
| void IsFomulaZero(char c[100]); | |
| int main() | |
| { | |
| char plusMS[12][2]; | |
| char minusMS[12][3]; | |
| for (int i = 0; i < 12; i++) | |
| { | |
| for (int j = 0; j < 2; j++) | |
| { | |
| plusMS[i][j] = -1; | |
| } | |
| for (int j = 0; j < 3; j++) | |
| { | |
| minusMS[i][j] = -1; | |
| } | |
| } | |
| plusMS[0][0] = '8'; | |
| plusMS[1][0] = '7'; | |
| plusMS[3][0] = '9'; | |
| plusMS[5][0] = '9'; | |
| plusMS[5][1] = '6'; | |
| plusMS[6][0] = '8'; | |
| plusMS[9][0] = '8'; | |
| plusMS[11][0] = '+'; | |
| minusMS[6][0] = '5'; | |
| minusMS[7][0] = '1'; | |
| minusMS[8][0] = '0'; | |
| minusMS[8][1] = '6'; | |
| minusMS[8][2] = '9'; | |
| minusMS[9][0] = '3'; | |
| minusMS[9][1] = '5'; | |
| minusMS[10][0] = '-'; | |
| char fomula[100]; | |
| scanf("%s", &fomula); | |
| int fomulaLen = strlen(fomula); | |
| for (int i = 0; i < fomulaLen; i++) | |
| { | |
| int temp = CTI(fomula[i]); | |
| char ostr = fomula[i]; | |
| for (int j = 0; j < 3; j++) | |
| { | |
| if (CTI(minusMS[temp][j]) != -1) | |
| { | |
| fomula[i] = minusMS[temp][j]; | |
| for (int k = 0; k < fomulaLen; k++) | |
| { | |
| if (i == k) continue; | |
| int temp2 = CTI(fomula[k]); | |
| char oostr = fomula[k]; | |
| for (int j = 0; j < 2; j++) | |
| { | |
| if (CTI(plusMS[temp2][j]) != -1) | |
| { | |
| fomula[k] = plusMS[temp2][j]; | |
| IsFomulaZero(fomula); | |
| } | |
| } | |
| fomula[k] = oostr; | |
| } | |
| } | |
| } | |
| fomula[i] = ostr; | |
| } | |
| } | |
| int CTI(char c) | |
| { | |
| switch (c) | |
| { | |
| case '0': | |
| return 0; | |
| break; | |
| case '1': | |
| return 1; | |
| break; | |
| case '2': | |
| return 2; | |
| break; | |
| case '3': | |
| return 3; | |
| break; | |
| case '4': | |
| return 4; | |
| break; | |
| case '5': | |
| return 5; | |
| break; | |
| case '6': | |
| return 6; | |
| break; | |
| case '7': | |
| return 7; | |
| break; | |
| case '8': | |
| return 8; | |
| break; | |
| case '9': | |
| return 9; | |
| break; | |
| case '+': | |
| return 10; | |
| break; | |
| case '-': | |
| return 11; | |
| break; | |
| default: | |
| return -1; | |
| break; | |
| } | |
| } | |
| void IsFomulaZero(char c[100]) | |
| { | |
| int sum = CTI(c[0]); | |
| int cLen = strlen(c); | |
| for (int i = 1; i < cLen; i+=2) | |
| { | |
| if (c[i] == '+') | |
| { | |
| sum += CTI(c[i + 1]); | |
| } | |
| else if (c[i] == '-') | |
| { | |
| sum -= CTI(c[i + 1]); | |
| } | |
| } | |
| if (sum == 0) | |
| printf("%s\n", c); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment