/*
Created By Rana Hamid
http://uvacode.blogspot.com/
+8801717623876
http://facebook.com/ranahamid07/
*/
//Converting Roman letter to number
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
//clrscr();
int *a,l,i,j,k;
char *s;
printf("Enter The Roman Number");
scanf("%s",s);
l=strlen(s);
for(i=0;i<l;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;
else
{
printf("Wrong Input");
getch();
exit(0);
}
}
k=a[l-1];
for(i=l-1;i>0;i--)
{
if(a[i]>a[i-1])
k=k-a[i-1];
else if(a[i]==a[i-1] || a[i]<a[i-1])
k=k+a[i-1];
}
printf("%d",k);
getch();
}
Created By Rana Hamid
http://uvacode.blogspot.com/
+8801717623876
http://facebook.com/ranahamid07/
*/
//Converting Roman letter to number
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
//clrscr();
int *a,l,i,j,k;
char *s;
printf("Enter The Roman Number");
scanf("%s",s);
l=strlen(s);
for(i=0;i<l;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;
else
{
printf("Wrong Input");
getch();
exit(0);
}
}
k=a[l-1];
for(i=l-1;i>0;i--)
{
if(a[i]>a[i-1])
k=k-a[i-1];
else if(a[i]==a[i-1] || a[i]<a[i-1])
k=k+a[i-1];
}
printf("%d",k);
getch();
}