#include #include #include #include #define MAX 1001 #define BASE 10 #define VECI(A,B) ((A)>(B)?(A):(B)) struct broj { int znam[MAX]; int brz; }; typedef struct broj broj; broj prvi, drugi; broj par[MAX]; broj sol; char oper; char screen[MAX][MAX]; int pos[MAX]; int head; int maxsize; void initscreen (void) { maxsize=0; head=0; } void push (char *s, int p) { pos[head]=p; strcpy(screen[head], s); if (p+strlen(s)>maxsize) maxsize=p+strlen(s); head++; } void dump (void) { int i, j; for (i=0; ibrz=1; a->znam[0]=0; } void add (broj *a, broj *b) { int i; int carry; int tmp; carry=0; for (i=0; ibrz || ibrz || carry>0; i++) { tmp=carry; if (ibrz) tmp+=a->znam[i]; if (ibrz) tmp+=b->znam[i]; a->znam[i]=tmp%BASE; carry=tmp/BASE; } a->brz=i; } void subtract (broj *a, broj *b) { int i; int carry; int tmp; carry=0; for (i=0; ibrz || ibrz || carry>0; i++) { tmp=a->znam[i]-carry; if (ibrz) tmp-=b->znam[i]; tmp+=BASE; a->znam[i]=tmp%BASE; carry=1-tmp/BASE; } while (a->znam[a->brz-1]==0) a->brz--; } void mult (broj *a, int b) { int i; int carry; int tmp; if (b==0) { zero(a); return ; } carry=0; for (i=0; ibrz || carry>0; i++) { tmp=carry; if (ibrz) tmp+=a->znam[i]*b; a->znam[i]=tmp%BASE; carry=tmp/BASE; } a->brz=i; } void shift (broj *a, int h) { int i; if (h==0) return ; for (i=a->brz-1; i>=0; i--) a->znam[i+h]=a->znam[i]; for (i=0; iznam[i]=0; a->brz+=h; } void print (broj a) { int i; for (i=a.brz-1; i>=0; i--) printf("%d", a.znam[i]); printf("\n"); } void read_input(void) { char tmp[MAX]; int i, l; scanf("\n%[0-9]", tmp); l=strlen(tmp); for (i=0; tmp[i]!=0; i++) prvi.znam[l-i-1]=tmp[i]-'0'; prvi.brz=l; while (l>0 && prvi.znam[prvi.brz-1]==0) prvi.brz--; scanf("%c", &oper); scanf("%[0-9]", tmp); l=strlen(tmp); for (i=0; tmp[i]!=0; i++) drugi.znam[l-i-1]=tmp[i]-'0'; drugi.brz=l; while (l>0 && drugi.znam[drugi.brz-1]==0) drugi.brz--; } void solve(void) { int i; char tmp[MAX]; initscreen(); tostr(prvi, tmp); push(tmp, 0); tmp[0]=oper; tostr(drugi, tmp+1); push(tmp, 0); if (oper=='+') { add(&prvi,&drugi); filld(VECI(prvi.brz, drugi.brz+1), tmp); push(tmp, 0); tostr(prvi, tmp); push(tmp, 0); } if (oper=='-') { subtract(&prvi,&drugi); filld(VECI(prvi.brz, drugi.brz+1), tmp); push(tmp, 0); tostr(prvi, tmp); push(tmp, 0); } if (oper=='*') { if (drugi.brz>1) { zero(&sol); for (i=0; i1) { filld(VECI(par[drugi.brz-1].brz, sol.brz), tmp); push(tmp, 0); tostr(sol, tmp); push(tmp, 0); } } else { mult(&prvi, drugi.znam[0]); filld(VECI(prvi.brz, drugi.brz+1), tmp); push(tmp, 0); tostr(prvi, tmp); push(tmp, 0); } } dump(); printf("\n"); } void write_output(void) { } int main() { int z, zz; scanf("%d", &zz); for (z=0; z