exp13
Anonymous
Plain Text
10/08/2025 6:52 AM
2.0 KB
14
Indexable
Never
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main() {
FILE *fin, *fout;
char ch = 'Z';
fin = fopen("input13.txt", "r");
fout = fopen("output1.txt", "w");
if (fin == NULL || fout == NULL) {
printf("Error opening file.\n");
return 1;
}
char buff[100];
char signs[20], op[20];
int signsl, opl;
printf("op\targ1\targ2\tresult\n");
while (fscanf(fin, "%s", buff) != EOF) {
signsl = opl = -1;
for (int i = 0; i < strlen(buff); i++) {
if (isalnum(buff[i])) {
signs[++signsl] = buff[i];
} else {
if (buff[i] == '*' || buff[i] == '/') {
while (opl >= 0 && (op[opl] == '*' || op[opl] == '/')) {
printf("%c\t%c\t%c\t%c\n", op[opl], signs[signsl - 1], signs[signsl], ch);
fprintf(fout, "%c\t%c\t%c\t%c\n", op[opl], signs[signsl - 1], signs[signsl], ch);
signsl--;
signs[signsl] = ch;
opl--;
ch--;
}
} else {
while (opl >= 0) {
printf("%c\t%c\t%c\t%c\n", op[opl], signs[signsl - 1], signs[signsl], ch);
fprintf(fout, "%c\t%c\t%c\t%c\n", op[opl], signs[signsl - 1], signs[signsl], ch);
signsl--;
signs[signsl] = ch;
opl--;
ch--;
}
}
op[++opl] = buff[i];
}
}
while (opl >= 0) {
printf("%c\t%c\t%c\t%c\n", op[opl], signs[signsl - 1], signs[signsl], ch);
fprintf(fout, "%c\t%c\t%c\t%c\n", op[opl], signs[signsl - 1], signs[signsl], ch);
signsl--;
signs[signsl] = ch;
opl--;
ch--;
}
}
fclose(fin);
fclose(fout);
return 0;
}Editor is loading...
Leave a Comment