Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- int t, i, j, k, l, d, x, y, z;
- char str[100000], str2[100000], str3[100000];
- void do_it()
- {
- puts("Enter your expression or press Any key to continue");
- }
- int isoperator(char ch)
- {
- if (ch == '+' || ch == '-' || ch == '/' || ch == '^' || ch == '*') return 1;
- return 0;
- }
- void check()
- {
- for (k = l - 1; ;k--)
- {
- if (str2[k] == ')' || str2[k] == '(') break;
- if (str2[k] == '.') continue;
- if ((str[j] == '-' || str[j] == '+' && ( (str2[k] == '*' || str2[k] == '/') || str2[k] == '^' )) || ( (str[j] == '*' || str[j] == '/') && str2[k] == '^'))
- {
- str3[d] = str2[k];
- d++;
- str2[k] = '.';
- }
- }
- str2[l] = str[j];
- l++;
- }
- void exodus()
- {
- for (j = strlen(str2); j >= 0; j--)
- {
- if (isoperator(str2[j]))
- {
- str3[d] = str2[j];
- d++;
- str2[j] = '.';
- }
- }
- str3[d] = '\0';
- }
- int main()
- {
- for (; ;)
- {
- do_it();
- gets(str);
- z = strcmp(str, "0");
- if (z == 0) break;
- d = 0, l = 1;
- str2[0] = ')';
- for (j = 0; str[j] != '\0'; j++)
- {
- if (str[j] == '(')
- {
- str2[l] = str[j];
- l++;
- }
- if (isalnum(str[j]))
- {
- str3[d] = str[j];
- d++;
- }
- if (isoperator(str[j])) check();
- if (str[j] == ')')
- {
- for (k = l - 1; str2[k] != '('; k--)
- {
- if (str2[k] == '.') continue;
- str3[d] = str2[k];
- d++;
- str2[k] = '.';
- }
- }
- }
- str2[l] = '\0';
- exodus();
- printf("%s\n", str3);
- puts("");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement