#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
int sum;
int rom_num(string x){
sum=0;
for(int i=0;i<x.size();i++){
if(x[i]=='I')
sum=sum+1;
else if(x[i]=='V')
sum=sum+5;
else if(x[i]=='X')
sum=sum+10;
else if(x[i]=='L')
sum=sum+50;
else if(x[i]=='C')
sum=sum+100;
else if(x[i]=='D')
sum=sum+500;
else
sum=sum+1000;
}
return sum;
}
void num_rom(int x){
while(x!=0){
if(x>=1000){
cout<<"M";
x=x-1000;
}
else if(x>=900){
cout<<"CM";
x=x-900;
}
else if(x>=500){
cout<<"D";
x=x-500;
}
else if(x>=400){
cout<<"CD";
x=x-400;
}
else if(x>=100){
cout<<"C";
x=x-100;
}
else if(x>=90){
cout<<"XC";
x=x-90;
}
else if(x>=50){
cout<<"L";
x=x-50;
}
else if(x>=40){
cout<<"XL";
x=x-40;
}
else if(x>=10){
cout<<"X";
x=x-10;
}
else if(x>=9){
cout<<"IX";
x=x-9;
}
else if(x>=5){
cout<<"V";
x=x-5;
}
else if(x>=4){
cout<<"IV";
x=x-4;
}
else{
cout<<"I";
x=x-1;
}
}
cout<<endl;
}
int main(){
int fin;
string a,b;
while(cin>>a&&a[0]!='#'){
cin>>b;
fin= abs(rom_num(a)-rom_num(b));
if(fin==0)
cout<<"ZERO"<<endl;
else
num_rom(fin);
}
}
#include
#include
#include
using namespace std;
int sum;
int rom_num(string x){
sum=0;
for(int i=0;i<x.size();i++){
if(x[i]=='I')
sum=sum+1;
else if(x[i]=='V')
sum=sum+5;
else if(x[i]=='X')
sum=sum+10;
else if(x[i]=='L')
sum=sum+50;
else if(x[i]=='C')
sum=sum+100;
else if(x[i]=='D')
sum=sum+500;
else
sum=sum+1000;
}
return sum;
}
void num_rom(int x){
while(x!=0){
if(x>=1000){
cout<<"M";
x=x-1000;
}
else if(x>=900){
cout<<"CM";
x=x-900;
}
else if(x>=500){
cout<<"D";
x=x-500;
}
else if(x>=400){
cout<<"CD";
x=x-400;
}
else if(x>=100){
cout<<"C";
x=x-100;
}
else if(x>=90){
cout<<"XC";
x=x-90;
}
else if(x>=50){
cout<<"L";
x=x-50;
}
else if(x>=40){
cout<<"XL";
x=x-40;
}
else if(x>=10){
cout<<"X";
x=x-10;
}
else if(x>=9){
cout<<"IX";
x=x-9;
}
else if(x>=5){
cout<<"V";
x=x-5;
}
else if(x>=4){
cout<<"IV";
x=x-4;
}
else{
cout<<"I";
x=x-1;
}
}
cout<<endl;
}
int main(){
int fin;
string a,b;
while(cin>>a&&a[0]!='#'){
cin>>b;
fin= abs(rom_num(a)-rom_num(b));
if(fin==0)
cout<<"ZERO"<<endl;
else
num_rom(fin);
}
}
我的也不行QQ