#include<stdio.h>
#include <stdlib.h>
int main(void){
char a,b;
int before,now,sum,num_1,num_2;
int broke=0;
while(1){
before=0;
sum=0;
while((a=getchar())!=' ')
{
if(a=='#'){broke=1; break;}
switch(a)
{
case 'I':now=1;break;
case 'V':now=5;break;
case 'X':now=10;break;
case 'L':now=50;break;
case 'C':now=100;break;
case 'D':now=500;break;
case 'M':now=1000;break;
}
sum+=now;
if(before<now) sum=sum-2*before;
before=now;
}
num_1=sum;
sum=0;
if(broke==1) break;
while((a=getchar())!='\n')
{
switch(a)
{
case 'I':now=1;break;
case 'V':now=5;break;
case 'X':now=10;break;
case 'L':now=50;break;
case 'C':now=100;break;
case 'D':now=500;break;
case 'M':now=1000;break;
}
sum+=now;
if(before<now) sum=sum-2*before;
before=now;
}
num_2=sum;
sum=abs(num_1-num_2);
if(sum==0)
{
printf("ZERO");
}
else
{
int p[4];
p[3]=sum%10;
sum/=10;
p[2]=sum%10;
sum/=10;
p[1]=sum%10;
sum/=10;
p[0]=sum%10;
switch(p[0])
{
case 0:break;
case 1:printf("M");break;
case 2:printf("MM");break;
case 3:printf("MMM");break;
case 4:printf("MMMM");break;
}
switch(p[1])
{
case 0:break;
case 1:printf("C");break;
case 2:printf("CC");break;
case 3:printf("CCC");break;
case 4:printf("CD");break;
case 5:printf("D");break;
case 6:printf("DC");break;
case 7:printf("DCC");break;
case 8:printf("DCCC");break;
case 9:printf("CM");break;
}
switch(p[2])
{
case 0:break;
case 1:printf("X");break;
case 2:printf("XX");break;
case 3:printf("XXX");break;
case 4:printf("XL");break;
case 5:printf("L");break;
case 6:printf("LX");break;
case 7:printf("LXX");break;
case 8:printf("LXXX");break;
case 9:printf("XC");break;
}
switch(p[3])
{
case 0:break;
case 1:printf("I");break;
case 2:printf("II");break;
case 3:printf("III");break;
case 4:printf("IV");break;
case 5:printf("V");break;
case 6:printf("VI");break;
case 7:printf("VII");break;
case 8:printf("VIII");break;
case 9:printf("IX");break;
}
}
printf("\n");
}
}
#include
#include
int main(void){
char a,b;
int before,now,sum,num_1,num_2;
int broke=0;
while(1){
before=0;
sum=0;
while((a=getchar())!=' ')
{
if(a=='#'){broke=1; break;}
switch(a)
{
case 'I':now=1;break;
case 'V':now=5;break;
case 'X':now=10;break;
case 'L':now=50;break;
case 'C':now=100;break;
case 'D':now=500;break;
case 'M':now=1000;break;
}
sum+=now;
if(before<now) sum=sum-2*before;
before=now;
}
num_1=sum;
sum=0;
if(broke==1) break;
while((a=getchar())!='\n')
{
switch(a)
{
case 'I':now=1;break;
case 'V':now=5;break;
case 'X':now=10;break;
case 'L':now=50;break;
case 'C':now=100;break;
case 'D':now=500;break;
case 'M':now=1000;break;
}
sum+=now;
if(before<now) sum=sum-2*before;
before=now;
}
num_2=sum;
sum=abs(num_1-num_2);
if(sum==0)
{
printf("ZERO");
}
else
{
int p[4];
p[3]=sum%10;
sum/=10;
p[2]=sum%10;
sum/=10;
p[1]=sum%10;
sum/=10;
p[0]=sum%10;
switch(p[0])
{
case 0:break;
case 1:printf("M");break;
case 2:printf("MM");break;
case 3:printf("MMM");break;
case 4:printf("MMMM");break;
}
switch(p[1])
{
case 0:break;
case 1:printf("C");break;
case 2:printf("CC");break;
case 3:printf("CCC");break;
case 4:printf("CD");break;
case 5:printf("D");break;
case 6:printf("DC");break;
case 7:printf("DCC");break;
case 8:printf("DCCC");break;
case 9:printf("CM");break;
}
switch(p[2])
{
case 0:break;
case 1:printf("X");break;
case 2:printf("XX");break;
case 3:printf("XXX");break;
case 4:printf("XL");break;
case 5:printf("L");break;
case 6:printf("LX");break;
case 7:printf("LXX");break;
case 8:printf("LXXX");break;
case 9:printf("XC");break;
}
switch(p[3])
{
case 0:break;
case 1:printf("I");break;
case 2:printf("II");break;
case 3:printf("III");break;
case 4:printf("IV");break;
case 5:printf("V");break;
case 6:printf("VI");break;
case 7:printf("VII");break;
case 8:printf("VIII");break;
case 9:printf("IX");break;
}
}
printf("\n");
}
}
忘記把一個地方歸0 已解出:>
#include<stdio.h>
#include <stdlib.h>
int main(void){
char a;
int before,now,sum,num_1,num_2;
int broke=0;
while(1){
before=0;
sum=0;
while((a=getchar())!=' ')
{
if(a=='#'){broke=1; break;}
switch(a)
{
case 'I':now=1;break;
case 'V':now=5;break;
case 'X':now=10;break;
case 'L':now=50;break;
case 'C':now=100;break;
case 'D':now=500;break;
case 'M':now=1000;break;
}
sum+=now;
if(before<now) sum=sum-2*before;
before=now;
}
num_1=sum;
sum=0;before=0;
if(broke==1) break;
while((a=getchar())!='\n')
{
switch(a)
{
case 'I':now=1;break;
case 'V':now=5;break;
case 'X':now=10;break;
case 'L':now=50;break;
case 'C':now=100;break;
case 'D':now=500;break;
case 'M':now=1000;break;
}
sum+=now;
if(before<now) sum=sum-2*before;
before=now;
}
num_2=sum;
sum=abs(num_1-num_2);
if(sum==0)
{
printf("ZERO");
}
else
{
int p[4]={0};
p[3]=sum%10;
sum/=10;
p[2]=sum%10;
sum/=10;
p[1]=sum%10;
sum/=10;
p[0]=sum%10;
switch(p[0])
{
case 0:break;
case 1:printf("M");break;
case 2:printf("MM");break;
case 3:printf("MMM");break;
case 4:printf("MMMM");break;
}
switch(p[1])
{
case 0:break;
case 1:printf("C");break;
case 2:printf("CC");break;
case 3:printf("CCC");break;
case 4:printf("CD");break;
case 5:printf("D");break;
case 6:printf("DC");break;
case 7:printf("DCC");break;
case 8:printf("DCCC");break;
case 9:printf("CM");break;
}
switch(p[2])
{
case 0:break;
case 1:printf("X");break;
case 2:printf("XX");break;
case 3:printf("XXX");break;
case 4:printf("XL");break;
case 5:printf("L");break;
case 6:printf("LX");break;
case 7:printf("LXX");break;
case 8:printf("LXXX");break;
case 9:printf("XC");break;
}
switch(p[3])
{
case 0:break;
case 1:printf("I");break;
case 2:printf("II");break;
case 3:printf("III");break;
case 4:printf("IV");break;
case 5:printf("V");break;
case 6:printf("VI");break;
case 7:printf("VII");break;
case 8:printf("VIII");break;
case 9:printf("IX");break;
}
}
printf("\n");
}
}