#include<bits/stdc++.h>
using namespace std;
int length(int);
int main()
{
int n,m,z,r,e=0,k,e2,line=0;
char c[3][2]={{'I','V'},
{'X','L'},
{'C','D'}};
int num[3][2]={{1,5},{10,50},{100,500}};
string a,b;
bool f=false,f2;
while(cin>>a)
{
e=-2;
e2=-1;
if(a=="#") break;
cin>>b;
//if(line==20) {cout<<a<<" "<<b<<endl;continue;}
if(a==b) {cout<<"ZERO\n";continue;}
string h;
int x=0;
n=0,m=0;
//f2=false;
for(int i=0;i<a.length();i++)
{
f=false;
for(int j=0;j<3;j++)
{
int g;
for( g=0;g<2;g++) if(a[i]==c[j][g]){k=num[j][g];f=true;break;}
if(f)
{
if(e==-2)
{
if(i==a.length()-1) n+=k;
e=k;
}
else if(e==k) n+=e+k,e=-2;
else if(k>e)
{
n+=k-e;
e=-2;
}
else if(e>k)
{
n+=(e!=1000)*e,e=k;
if(i==a.length()-1) n+=k;
}
break;
}
}
if(f==false)
{
if(e==-2) n+=1000;
else if(e==1000) n+=1000;
else if(e==-1) n+=1000;
else if(e<1000) n+=1000-e;
else n+=1000+e;
e=1000;
}
}
//if(a.length()==1||f2) n+=e;
//cout<<n<<" ";
e=-2;
f2=false;
for(int i=0;i<b.length();i++)
{
f=false;
for(int j=0;j<3;j++)
{
int g;
for( g=0;g<2;g++) if(b[i]==c[j][g]){k=num[j][g];f=true;break;}
if(f)
{
if(e==-2)
{
if(i==b.length()-1) m+=k;
e=k;
}
else if(e==k) m+=e+k,e=-2;
else if(k>e)
{
m+=k-e;
e=-2;
}
else if(e>k)
{
m+=(e!=1000)*e,e=k;
if(i==b.length()-1) m+=k;
}
break;
}
}
if(f==false)
{
if(e==-2) m+=1000;
else if(e==1000) m+=1000;
else if(e==-1) m+=1000;
else if(e<1000) m+=1000-e;
else m+=1000+e;
e=1000;
}
// cout<<m<<" ";
}
//if(b.length()==1||f2) m+=e;
//cout<<m<<" ";
x=abs(n-m);
//x=444;
//cout<<x<<endl;
if(x==0) {cout<<"ZERO\n";continue;}
string s;
int p,l;
l=length(x);
while(l>1)
{
p=pow(10,l-1);
if(x/p==0) s+='0';
else s+=x/p+'0';
x%=p;
l--;
//cout<<s<<" ";
}
s+=x+'0';
//cout<<s<<endl;
r=0;
for(int i=s.length()-1;i>=0;i--)
{
if(s[i]=='0') {r++;continue;}
if(s.length()-i-1==3) for(int j=0;j<s[i]-'0';j++) h+='M';
else
{
if(s[i]>='5'&&s[i]<'9'){
//cout<<c[s.length()-i-1][0];
for(int mm=0;mm<(s[i]-'5');mm++) h+=c[s.length()-i-1][0];
//cout<<h.length()<<endl;
h+=c[s.length()-i-1][1];
r=0;
}
else if(s[i]=='9')
{
if(s.length()-i==3) h+='M';
else h+=c[s.length()-i][0];
h+=c[s.length()-1-i][0];
r=0;
}
else if(s[i]=='4')
{
h+=c[s.length()-i-1][1];
h+=c[s.length()-1-i][0];
r=0;
}
else
{
for(int mm=0;mm<s[i]-'0';mm++) h+=c[s.length()-i-1][0];
r=0;
}
}
}
string h2;
for(int i=h.length()-1;i>=0;i--) h2+=h[i];
/* if(h2=="MMDCCLXIII")
{
cout<<a<<"|"<<b<<endl;
continue;
}*/
cout<<h2<<endl;
}
}
int length(int n)
{
int num=1;
while(n>=10) n/=10,num++;
return num;
}
#include<bits/stdc++.h>
using namespace std;
int length(int);
int main()
{
int n,m,z,r,e=0,k,e2,line=0;
char c[3][2]={{'I','V'},
{'X','L'},
{'C','D'}};
int num[3][2]={{1,5},{10,50},{100,500}};
string a,b;
bool f=false,f2;
while(cin>>a)
{
e=-2;
e2=-1;
if(a=="#") break;
cin>>b;
//if(line==20) {cout<<a<<" "<<b<<endl;continue;}
if(a==b) {cout<<"ZERO\n";continue;}
string h;
int x=0;
n=0,m=0;
//f2=false;
for(int i=0;i<a.length();i++)
{
f=false;
for(int j=0;j<3;j++)
{
int g;
for( g=0;g<2;g++) if(a[i]==c[j][g]){k=num[j][g];f=true;break;}
if(f)
{
if(e==-2)
{
if(i==a.length()-1) n+=k;
e=k;
}
else if(e==k) n+=e+k,e=-2;
else if(k>e)
{
n+=k-e;
e=-2;
}
else if(e>k)
{
n+=(e!=1000)*e,e=k;
if(i==a.length()-1) n+=k;
}
break;
}
}
if(f==false)
{
if(e==-2) n+=1000;
else if(e==1000) n+=1000;
else if(e==-1) n+=1000;
else if(e<1000) n+=1000-e;
else n+=1000+e;
e=1000;
}
}
//if(a.length()==1||f2) n+=e;
//cout<<n<<" ";
e=-2;
f2=false;
for(int i=0;i<b.length();i++)
{
f=false;
for(int j=0;j<3;j++)
{
int g;
for( g=0;g<2;g++) if(b[i]==c[j][g]){k=num[j][g];f=true;break;}
if(f)
{
if(e==-2)
{
if(i==b.length()-1) m+=k;
e=k;
}
else if(e==k) m+=e+k,e=-2;
else if(k>e)
{
m+=k-e;
e=-2;
}
else if(e>k)
{
m+=(e!=1000)*e,e=k;
if(i==b.length()-1) m+=k;
}
break;
}
}
if(f==false)
{
if(e==-2) m+=1000;
else if(e==1000) m+=1000;
else if(e==-1) m+=1000;
else if(e<1000) m+=1000-e;
else m+=1000+e;
e=1000;
}
// cout<<m<<" ";
}
//if(b.length()==1||f2) m+=e;
//cout<<m<<" ";
x=abs(n-m);
//x=444;
//cout<<x<<endl;
if(x==0) {cout<<"ZERO\n";continue;}
string s;
int p,l;
l=length(x);
while(l>1)
{
p=pow(10,l-1);
if(x/p==0) s+='0';
else s+=x/p+'0';
x%=p;
l--;
//cout<<s<<" ";
}
s+=x+'0';
//cout<<s<<endl;
r=0;
for(int i=s.length()-1;i>=0;i--)
{
if(s[i]=='0') {r++;continue;}
if(s.length()-i-1==3) for(int j=0;j<s[i]-'0';j++) h+='M';
else
{
if(s[i]>='5'&&s[i]<'9'){
//cout<<c[s.length()-i-1][0];
for(int mm=0;mm<(s[i]-'5');mm++) h+=c[s.length()-i-1][0];
//cout<<h.length()<<endl;
h+=c[s.length()-i-1][1];
r=0;
}
else if(s[i]=='9')
{
if(s.length()-i==3) h+='M';
else h+=c[s.length()-i][0];
h+=c[s.length()-1-i][0];
r=0;
}
else if(s[i]=='4')
{
h+=c[s.length()-i-1][1];
h+=c[s.length()-1-i][0];
r=0;
}
else
{
for(int mm=0;mm<s[i]-'0';mm++) h+=c[s.length()-i-1][0];
r=0;
}
}
}
string h2;
for(int i=h.length()-1;i>=0;i--) h2+=h[i];
/* if(h2=="MMDCCLXIII")
{
cout<<a<<"|"<<b<<endl;
continue;
}*/
cout<<h2<<endl;
}
}
int length(int n)
{
int num=1;
while(n>=10) n/=10,num++;
return num;
}
這是我的寫法
建好表比較簡潔
#include <bits/stdc++.h>
using namespace std;
char c[7]={'I','V','X','L','C','D','M'};
int cc[7]={1,5,10,50,100,500,1000};
string ccc[13]={"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
int cccc[13]={1,4,5,9,10,40,50,90,100,400,500,900,1000};
int ch(char a){
for(int b=0;b<7;b++)
if(a==c[b])
return b;
}
int in(string a){
int d=0;
for(int b=0;b<a.size();b++){
if(!(b+1==a.size())&&ch(a[b])<ch(a[b+1]))
d-=cc[ch(a[b])];
else
d+=cc[ch(a[b])];
}
return d;
}
void out(int a){
if(a==0)
cout<<"ZERO"<<endl;
else{
string b="";
for(int d=12;d>=0;d--){
for(int e=0;e<a/cccc[d];e++)
b+=ccc[d];
a%=cccc[d];
}
cout<<b<<endl;
}
}
int main(){
string a,b;
while(cin>>a&&a[0]!='#'){
cin>>b;
out(abs(in(a)-in(b)));
}
}
#include<bits/stdc++.h>
using namespace std;
int length(int);
int main()
{
int n,m,z,r,e=0,k,e2,line=0;
char c[3][2]={{'I','V'},
{'X','L'},
{'C','D'}};
int num[3][2]={{1,5},{10,50},{100,500}};
string a,b;
bool f=false,f2;
while(cin>>a)
{
e=-2;
e2=-1;
if(a=="#") break;
cin>>b;
//if(line==20) {cout<<a<<" "<<b<<endl;continue;}
if(a==b) {cout<<"ZERO\n";continue;}
string h;
int x=0;
n=0,m=0;
//f2=false;
for(int i=0;i<a.length();i++)
{
f=false;
for(int j=0;j<3;j++)
{
int g;
for( g=0;g<2;g++) if(a[i]==c[j][g]){k=num[j][g];f=true;break;}
if(f)
{
if(e==-2)
{
if(i==a.length()-1) n+=k;
e=k;
}
else if(e==k) n+=e+k,e=-2;
else if(k>e)
{
n+=k-e;
e=-2;
}
else if(e>k)
{
n+=(e!=1000)*e,e=k;
if(i==a.length()-1) n+=k;
}
break;
}
}
if(f==false)
{
if(e==-2) n+=1000;
else if(e==1000) n+=1000;
else if(e==-1) n+=1000;
else if(e<1000) n+=1000-e;
else n+=1000+e;
e=1000;
}
}
//if(a.length()==1||f2) n+=e;
//cout<<n<<" ";
e=-2;
f2=false;
for(int i=0;i<b.length();i++)
{
f=false;
for(int j=0;j<3;j++)
{
int g;
for( g=0;g<2;g++) if(b[i]==c[j][g]){k=num[j][g];f=true;break;}
if(f)
{
if(e==-2)
{
if(i==b.length()-1) m+=k;
e=k;
}
else if(e==k) m+=e+k,e=-2;
else if(k>e)
{
m+=k-e;
e=-2;
}
else if(e>k)
{
m+=(e!=1000)*e,e=k;
if(i==b.length()-1) m+=k;
}
break;
}
}
if(f==false)
{
if(e==-2) m+=1000;
else if(e==1000) m+=1000;
else if(e==-1) m+=1000;
else if(e<1000) m+=1000-e;
else m+=1000+e;
e=1000;
}
// cout<<m<<" ";
}
//if(b.length()==1||f2) m+=e;
//cout<<m<<" ";
x=abs(n-m);
//x=444;
//cout<<x<<endl;
if(x==0) {cout<<"ZERO\n";continue;}
string s;
int p,l;
l=length(x);
while(l>1)
{
p=pow(10,l-1);
if(x/p==0) s+='0';
else s+=x/p+'0';
x%=p;
l--;
//cout<<s<<" ";
}
s+=x+'0';
//cout<<s<<endl;
r=0;
for(int i=s.length()-1;i>=0;i--)
{
if(s[i]=='0') {r++;continue;}
if(s.length()-i-1==3) for(int j=0;j<s[i]-'0';j++) h+='M';
else
{
if(s[i]>='5'&&s[i]<'9'){
//cout<<c[s.length()-i-1][0];
for(int mm=0;mm<(s[i]-'5');mm++) h+=c[s.length()-i-1][0];
//cout<<h.length()<<endl;
h+=c[s.length()-i-1][1];
r=0;
}
else if(s[i]=='9')
{
if(s.length()-i==3) h+='M';
else h+=c[s.length()-i][0];
h+=c[s.length()-1-i][0];
r=0;
}
else if(s[i]=='4')
{
h+=c[s.length()-i-1][1];
h+=c[s.length()-1-i][0];
r=0;
}
else
{
for(int mm=0;mm<s[i]-'0';mm++) h+=c[s.length()-i-1][0];
r=0;
}
}
}
string h2;
for(int i=h.length()-1;i>=0;i--) h2+=h[i];
/* if(h2=="MMDCCLXIII")
{
cout<<a<<"|"<<b<<endl;
continue;
}*/
cout<<h2<<endl;
}
}
int length(int n)
{
int num=1;
while(n>=10) n/=10,num++;
return num;
}
這是我的寫法
建好表比較簡潔
#include <bits/stdc++.h>
using namespace std;
char c[7]={'I','V','X','L','C','D','M'};
int cc[7]={1,5,10,50,100,500,1000};
string ccc[13]={"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
int cccc[13]={1,4,5,9,10,40,50,90,100,400,500,900,1000};
int ch(char a){
for(int b=0;b<7;b++)
if(a==c[b])
return b;
}
int in(string a){
int d=0;
for(int b=0;b<a.size();b++){
if(!(b+1==a.size())&&ch(a[b])<ch(a[b+1]))
d-=cc[ch(a[b])];
else
d+=cc[ch(a[b])];
}
return d;
}
void out(int a){
if(a==0)
cout<<"ZERO"<<endl;
else{
string b="";
for(int d=12;d>=0;d--){
for(int e=0;e<a/cccc[d];e++)
b+=ccc[d];
a%=cccc[d];
}
cout<<b<<endl;
}
}
int main(){
string a,b;
while(cin>>a&&a[0]!='#'){
cin>>b;
out(abs(in(a)-in(b)));
}
}
新的寫法:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
char c[7]={'I', 'V', 'X', 'L', 'C', 'D', 'M'};
int n[7]={1, 5, 10, 50, 100, 500, 1000};
string s2[2];
while(cin>>s2[0]&&s2[0]!="#")
{
cin>>s2[1];
int l[2];
for(int r=0;r<2;r++)
{
string s=s2[r];
//cout<<s<<" ";
l[r]=0;
char a='z';
for(int i=s.length()-1;i>=0;i--)
{
if(a=='z')
{
//cout<<find(c,c+7,s[i])-c<<" ";
l[r]+=n[find(c,c+7,s[i])-c];
a=s[i];
}
else
{
if(find(c,c+7,s[i])-c<find(c,c+7,a)-c)
{
l[r]-=n[find(c,c+7,s[i])-c];
a='z';
}
else
{
l[r]+=n[find(c,c+7,s[i])-c];
a=s[i];
}
}
//cout<<l[r]<<" ";
}
}
int num=abs(l[0]-l[1]);
//cout<<num<<" ";
if(!num) {cout<<"ZERO\n";continue;
}
stringstream ss;
ss<<num;
string s;
ss>>s;
for(int i=0;i<s.length();i++)
{
if(s[i]=='0') continue;
if(s.length()-i-1==3) cout<<string(s[i]-'0','M');
else
{
int p=pow(10,s.length()-i-1);
if(s[i]=='9'||s[i]=='4')
{
cout<<c[find(n,n+7,p)-n]<<c[find(n,n+7,p*(s[i]-'0'+1))-n];
}
else
{
if(s[i]>='5') cout<<c[find(n,n+7,5*p)-n];
cout<<string((s[i]-'0')%5,c[find(n,n+7,p)-n]);
//cout<<"p"<<p<<"\n";
}
}
}
cout<<"\n";
}
}
AC (2ms, 324KB) |
#include<bits/stdc++.h>
using namespace std;
int length(int);
int main()
{
int n,m,z,r,e=0,k,e2,line=0;
char c[3][2]={{'I','V'},
{'X','L'},
{'C','D'}};
int num[3][2]={{1,5},{10,50},{100,500}};
string a,b;
bool f=false,f2;
while(cin>>a)
{
e=-2;
e2=-1;
if(a=="#") break;
cin>>b;
//if(line==20) {cout<<a<<" "<<b<<endl;continue;}
if(a==b) {cout<<"ZERO\n";continue;}
string h;
int x=0;
n=0,m=0;
//f2=false;
for(int i=0;i<a.length();i++)
{
f=false;
for(int j=0;j<3;j++)
{
int g;
for( g=0;g<2;g++) if(a[i]==c[j][g]){k=num[j][g];f=true;break;}
if(f)
{
if(e==-2)
{
if(i==a.length()-1) n+=k;
e=k;
}
else if(e==k) n+=e+k,e=-2;
else if(k>e)
{
n+=k-e;
e=-2;
}
else if(e>k)
{
n+=(e!=1000)*e,e=k;
if(i==a.length()-1) n+=k;
}
break;
}
}
if(f==false)
{
if(e==-2) n+=1000;
else if(e==1000) n+=1000;
else if(e==-1) n+=1000;
else if(e<1000) n+=1000-e;
else n+=1000+e;
e=1000;
}
}
//if(a.length()==1||f2) n+=e;
//cout<<n<<" ";
e=-2;
f2=false;
for(int i=0;i<b.length();i++)
{
f=false;
for(int j=0;j<3;j++)
{
int g;
for( g=0;g<2;g++) if(b[i]==c[j][g]){k=num[j][g];f=true;break;}
if(f)
{
if(e==-2)
{
if(i==b.length()-1) m+=k;
e=k;
}
else if(e==k) m+=e+k,e=-2;
else if(k>e)
{
m+=k-e;
e=-2;
}
else if(e>k)
{
m+=(e!=1000)*e,e=k;
if(i==b.length()-1) m+=k;
}
break;
}
}
if(f==false)
{
if(e==-2) m+=1000;
else if(e==1000) m+=1000;
else if(e==-1) m+=1000;
else if(e<1000) m+=1000-e;
else m+=1000+e;
e=1000;
}
// cout<<m<<" ";
}
//if(b.length()==1||f2) m+=e;
//cout<<m<<" ";
x=abs(n-m);
//x=444;
//cout<<x<<endl;
if(x==0) {cout<<"ZERO\n";continue;}
string s;
int p,l;
l=length(x);
while(l>1)
{
p=pow(10,l-1);
if(x/p==0) s+='0';
else s+=x/p+'0';
x%=p;
l--;
//cout<<s<<" ";
}
s+=x+'0';
//cout<<s<<endl;
r=0;
for(int i=s.length()-1;i>=0;i--)
{
if(s[i]=='0') {r++;continue;}
if(s.length()-i-1==3) for(int j=0;j<s[i]-'0';j++) h+='M';
else
{
if(s[i]>='5'&&s[i]<'9'){
//cout<<c[s.length()-i-1][0];
for(int mm=0;mm<(s[i]-'5');mm++) h+=c[s.length()-i-1][0];
//cout<<h.length()<<endl;
h+=c[s.length()-i-1][1];
r=0;
}
else if(s[i]=='9')
{
if(s.length()-i==3) h+='M';
else h+=c[s.length()-i][0];
h+=c[s.length()-1-i][0];
r=0;
}
else if(s[i]=='4')
{
h+=c[s.length()-i-1][1];
h+=c[s.length()-1-i][0];
r=0;
}
else
{
for(int mm=0;mm<s[i]-'0';mm++) h+=c[s.length()-i-1][0];
r=0;
}
}
}
string h2;
for(int i=h.length()-1;i>=0;i--) h2+=h[i];
/* if(h2=="MMDCCLXIII")
{
cout<<a<<"|"<<b<<endl;
continue;
}*/
cout<<h2<<endl;
}
}
int length(int n)
{
int num=1;
while(n>=10) n/=10,num++;
return num;
}
這是我的寫法
建好表比較簡潔
#include <bits/stdc++.h>
using namespace std;
char c[7]={'I','V','X','L','C','D','M'};
int cc[7]={1,5,10,50,100,500,1000};
string ccc[13]={"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
int cccc[13]={1,4,5,9,10,40,50,90,100,400,500,900,1000};
int ch(char a){
for(int b=0;b<7;b++)
if(a==c[b])
return b;
}
int in(string a){
int d=0;
for(int b=0;b<a.size();b++){
if(!(b+1==a.size())&&ch(a[b])<ch(a[b+1]))
d-=cc[ch(a[b])];
else
d+=cc[ch(a[b])];
}
return d;
}
void out(int a){
if(a==0)
cout<<"ZERO"<<endl;
else{
string b="";
for(int d=12;d>=0;d--){
for(int e=0;e<a/cccc[d];e++)
b+=ccc[d];
a%=cccc[d];
}
cout<<b<<endl;
}
}
int main(){
string a,b;
while(cin>>a&&a[0]!='#'){
cin>>b;
out(abs(in(a)-in(b)));
}
}
新的寫法:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
char c[7]={'I', 'V', 'X', 'L', 'C', 'D', 'M'};
int n[7]={1, 5, 10, 50, 100, 500, 1000};
string s2[2];
while(cin>>s2[0]&&s2[0]!="#")
{
cin>>s2[1];
int l[2];
for(int r=0;r<2;r++)
{
string s=s2[r];
//cout<<s<<" ";
l[r]=0;
char a='z';
for(int i=s.length()-1;i>=0;i--)
{
if(a=='z')
{
//cout<<find(c,c+7,s[i])-c<<" ";
l[r]+=n[find(c,c+7,s[i])-c];
a=s[i];
}
else
{
if(find(c,c+7,s[i])-c<find(c,c+7,a)-c)
{
l[r]-=n[find(c,c+7,s[i])-c];
a='z';
}
else
{
l[r]+=n[find(c,c+7,s[i])-c];
a=s[i];
}
}
//cout<<l[r]<<" ";
}
}
int num=abs(l[0]-l[1]);
//cout<<num<<" ";
if(!num) {cout<<"ZERO\n";continue;
}
stringstream ss;
ss<<num;
string s;
ss>>s;
for(int i=0;i<s.length();i++)
{
if(s[i]=='0') continue;
if(s.length()-i-1==3) cout<<string(s[i]-'0','M');
else
{
int p=pow(10,s.length()-i-1);
if(s[i]=='9'||s[i]=='4')
{
cout<<c[find(n,n+7,p)-n]<<c[find(n,n+7,p*(s[i]-'0'+1))-n];
}
else
{
if(s[i]>='5') cout<<c[find(n,n+7,5*p)-n];
cout<<string((s[i]-'0')%5,c[find(n,n+7,p)-n]);
//cout<<"p"<<p<<"\n";
}
}
}
cout<<"\n";
}
}
AC (2ms, 324KB) |
#include <iostream>
#include <cmath>
using namespace std;
int a[1000];
int r2i(string s){
int sum=0;
for(int i=0;i<s.length();i++){
if(s[i]=='I')a[i]=1;
else if(s[i]=='V')a[i]=5;
else if(s[i]=='X')a[i]=10;
else if(s[i]=='L')a[i]=50;
else if(s[i]=='C')a[i]=100;
else if(s[i]=='D')a[i]=500;
else if(s[i]=='M')a[i]=1000;
}
for(int i=0;i<s.length()-1;i++){
if(a[i]<a[i+1])a[i]*=-1;
}
for(int i=0;i<s.length();i++){
sum+=a[i];
}
return sum;
}
string i2r(int n){
string s;
while(n>0){
if(n>=1000){s+="M";n-=1000;}
else if(n>=900){s+="CM";n-=900;}
else if(n>=500){s+="D";n-=500;}
else if(n>=400){s+="CD";n-=400;}
else if(n>=100){s+="C";n-=100;}
else if(n>=90){s+="XC";n-=90;}
else if(n>=50){s+="L";n-=50;}
else if(n>=40){s+="XL";n-=40;}
else if(n>=10){s+="X";n-=10;}
else if(n>=9){s+="IX";n-=9;}
else if(n>=5){s+="V";n-=5;}
else if(n>=4){s+="IV";n-=4;}
else if(n>=1){s+="I";n-=1;}
}
return s;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
string s1,s2;
while(cin>>s1>>s2){
if(s1=="#")return 0;
if(s1==s2){
cout<<"ZERO\n";
continue;
}
int sum1,sum2;
sum1=r2i(s1);
sum2=r2i(s2);
cout<<i2r(abs(sum1-sum2))<<"\n";
}
}
#我的寫法