ammmmmgoding @ 2023-11-06 22:26:44
#include <stdio.h>
#include <string.h>
int len(int b, int c, char t) {
int o = 0;int count = 0;
if (t == '+') { o = b + c; }
if (t == '-') { o = b - c; }
if (t == '*') { o = b * c; }
while (b > 0) { b /= 10; count++; }while (c > 0) { c /= 10; count++; }while (o != 0) { if (o > 0) { o /= 10; count++; } else { o *= (-1); } }return count;
}
int main() {
int u[100] = { 0 };
int n = 0; scanf("%d", &n); char t[100]; int b[100] = { 0 }, c[100] = { 0 };
for (int i = 0; i < n; i++) {
if (scanf("%d %d", &b[i], &c[i]) == 2) {
if (t[i - 1] == 'a') { u[i] = len(b[i], c[i], '+') + 2; t[i] = 'a'; }
if (t[i - 1] == 'b') {
if (b[i] - c[i] < 0)u[i] = len(b[i], c[i], '-') + 3; else { u[i] = len(b[i], c[i], '-') + 2; } t[i] = 'b';
}
if (t[i - 1] == 'c') { u[i] = len(b[i], c[i], '*') + 2; t[i] = 'c';
}
} else {
scanf("%c %d %d", &t[i], &b[i], &c[i]); if (t[i] == 'a') { u[i] = len(b[i], c[i], '+') + 2; }
if (t[i] == 'b') {
if (b[i] - c[i] < 0)u[i] = len(b[i], c[i], '-') + 3; else u[i] = len(b[i], c[i], '-') + 2;
}
if (t[i] == 'c') { u [i] = len(b[i], c[i], '*') + 2; }
}}
for(int i=0;i<n;i++){
if (t[i] == 'a') { printf("%d+%d=%d\n%d\n", b[i], c[i], b[i] + c[i], u[i]); }
if (t[i] == 'b') { printf("%d-%d=%d\n%d\n", b[i], c[i], b[i] - c[i], u[i]); }
if (t[i] == 'c') { printf("%d*%d=%d\n%d\n", b[i], c[i], b[i] * c[i], u[i]); }
}
return 0;
}