1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| #include<bits/stdc++.h> using namespace std; typedef long long ll; #define per(i,a,n) for (int i=a;i<n;i++) #define rep(i,a,n) for (int i=n-1;i>=a;i--)
const int MAXN(1e6); int T; string a, b, c, tmpa, tmpb, tmpc; ll znum[3]; int len1, len2, len3;
inline void Reduce(string &c, string &a, int& lenc, int& lena) { int pa=lena-1, pc=lenc-1; int flag=0; string ptr; while(pa>=0 && pc>=0) { flag = c[pc--]-'0'-(a[pa--]-'0')-flag; if(flag<0) { flag+=10; ptr+=flag+'0'; flag = 1; } else { ptr+=flag+'0'; flag = 0; } } while(pc>=0) { flag = c[pc--] - '0' - flag; if(flag<0) { flag+=10; ptr+=flag+'0'; flag = 1; } else { ptr+=flag+'0'; flag = 0; } } lenc = ptr.length(); rep(i, 0, lenc) {if(ptr[i]!='0'){lenc=i+1;ptr=ptr.substr(0,lenc);break;}} c=string(); per(i, 0, lenc) { c+=ptr[lenc-1-i]; } }
int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> T; while(T--) { cin >> a >> b >> c; fill(znum, znum+3, 0); len1=a.length(); len2=b.length(); len3=c.length(); rep(i, 0, len1) {if(a[i]=='0'){znum[0]++;} else {break;}} rep(i, 0, len2) {if(b[i]=='0'){znum[1]++;} else {break;}} rep(i, 0, len3) {if(c[i]=='0'){znum[2]++;} else {break;}} len1-=znum[0]; len2-=znum[1]; len3-=znum[2]; a=a.substr(0,len1); b=b.substr(0,len2); c=c.substr(0,len3); { tmpa = a; tmpb = b; tmpc = c; int tmpl1=len1, tmpl2=len2, tmpl3=len3; int tmpznm[3]; tmpznm[0]=znum[0]; tmpznm[1]=znum[1]; tmpznm[2]=znum[2]; if (tmpl1 > tmpl3) { tmpc += string(tmpl1 - tmpl3, '0'); tmpznm[2] -= (tmpl1-tmpl3); tmpl3=tmpl1; } if(tmpl1==tmpl3) { per(i, 0, tmpl1) { if(tmpa[i]>tmpc[i]) { tmpc+='0'; tmpl3++; tmpznm[2]--; break; } else if(tmpa[i]<tmpc[i]) { break; } } } Reduce(tmpc, tmpa, tmpl3, tmpl1); rep(i, 0, tmpl3) {if(tmpc[i]=='0'){tmpznm[2]++;tmpznm[0]++;} else {tmpc=tmpc.substr(0, i+1);break;}} if(tmpc==tmpb) { int anso=max(tmpznm[0], tmpznm[1]); anso = max(anso, tmpznm[2]); tmpznm[0] = anso-tmpznm[0]; tmpznm[1] = anso-tmpznm[1]; tmpznm[2] = anso-tmpznm[2]; if(tmpznm[0]<=MAXN && tmpznm[1]<=MAXN && tmpznm[2]<=MAXN) { cout << tmpznm[0] << ' ' << tmpznm[1] << ' ' << tmpznm[2] << '\n'; continue; } } } { tmpa = b; tmpb = a; tmpc = c; int tmpl1=len2, tmpl2=len1, tmpl3=len3; int tmpznm[3]; tmpznm[0]=znum[1]; tmpznm[1]=znum[0]; tmpznm[2]=znum[2]; if (tmpl1 > tmpl3) { tmpc += string(tmpl1 - tmpl3, '0'); tmpznm[2] -= (tmpl1-tmpl3); tmpl3=tmpl1; } if(tmpl1==tmpl3) { per(i, 0, tmpl1) { if(tmpa[i]>tmpc[i]) { tmpc+='0'; tmpl3++; tmpznm[2]--; break; } else if(tmpa[i]<tmpc[i]) { break; } } } Reduce(tmpc, tmpa, tmpl3, tmpl1); rep(i, 0, tmpl3) {if(tmpc[i]=='0'){tmpznm[2]++;tmpznm[0]++;} else {tmpc=tmpc.substr(0, i+1);break;}} if(tmpc==tmpb) { int anso=max(tmpznm[0], tmpznm[1]); anso = max(anso, tmpznm[2]); tmpznm[0] = anso-tmpznm[0]; tmpznm[1] = anso-tmpznm[1]; tmpznm[2] = anso-tmpznm[2]; if(tmpznm[0]<=MAXN && tmpznm[1]<=MAXN && tmpznm[2]<=MAXN) { cout << tmpznm[1] << ' ' << tmpznm[0] << ' ' << tmpznm[2] << '\n'; continue; } } } cout << "-1\n"; }
return 0; }
|