Advertisement
1_2002 OLE/ COM/ DCOM/ Active-X #111489

Convert_Roman_Nos.

THIS IS THE "FASTEST" ALGORITHM FOR CONVERSION OF ROMAN NUMERALS INTO NUMBERS.IT WILL CONVERT ALL ROMAN NUMERALS INTO NUMBERS IN RECORD TIME.IF ANY ONE KNOWS ANY FASTER METHOD PLEASE LET ME KNOW.

AI

Shrnutí AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Zdrojový kód
original-source
#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
//For Any Queries,MailMe [email protected] 
void main()
{
char a[15];
cout<<"Enter The Roman Number :"; 	
cin>>a;
for(int x=0,p=0,flag=0,rom=0,int i=strlen(a)-1;i>=0;i--)
	{
	if (a[i]=='i' || a[i]=='I') x=1; 
    if (a[i]=='v' || a[i]=='V') x=5; 
	if (a[i]=='x' || a[i]=='X') x=10; 
	if (a[i]=='l' || a[i]=='L') x=50; 
	if (a[i]=='c' || a[i]=='C') x=100; 
	if (a[i]=='d' || a[i]=='D') x=500;
	if (a[i]=='m' || a[i]=='M') x=1000; 
 	
	if (x<p) flag = -1; 
	else flag = 1;
 
	rom= rom + (x*flag);
	p=x;	//storing the previous value in x
	}
cout<<"Numerical value is : "<<rom;
getch();
}
Původní komentáře (3)
Obnoveno z Wayback Machine