#include<iostream>
#include<fstream>
#include<conio.h>
#include<string.h>
using namespace std;
int f(char a)
{
char b[8]="XLCDIMV";
int b1[7];
b1[0]=10;
b1[1]=50;
b1[2]=100;
b1[3]=500;
b1[4]=1;
b1[5]=1000;
b1[6]=5;
for(int i=0;i<7;i++)
{
if(b[i]==a)
return b1[i];
}
}
int main()
{
ofstream fout("output.txt");
ifstream fin("input.txt");
char ad[30];
int t[30],al[30];
fin>>ad;
for(int i=0;i<strlen(ad);i++)
t[i]=f(ad[i]);
al[strlen(ad)-1]=1;
for(int i=strlen(ad)-2;i>-1;i--)
{
if(t[i]<t[i+1])
al[i]=-1;
else
al[i]=1;
}
int ans=0;
for(int i=0;i<strlen(ad);i++)
ans=ans+al[i]*t[i];
fout<<ans<<endl;
getch();
return 0;
}
User:Erfankh
Pr: RomanNumeral
Testing....
compiling...
compile error! Why did you use getch?
Removing getch....
Penalty:Score-=5
compiling...
compiled!
Test results:
Test 1: Pass
Test 2: Pass
Test 3: Runtime error!
!Test 4:Runtime error
Test 5:Runtime error!
Total score=2/5*100-5= 35
[CENTER][B]14[/B][/CENTER]
[TABLE][TR] [TD]
[B]:كد[/B][/TD] [/TR] [TR] [TD]User:Erfankh
Pr: RomanNumeral
Testing....
compiling...
compile error! Why did you use getch?
Removing getch....
Penalty:Score-=5
compiling...
compiled!
Test results:
Test 1: Pass
Test 2: Pass
Test 3: Runtime error!
!Test 4:Runtime error
Test 5:Runtime error!
Total score=2/5*100-5= 35[/TD] [/TR][/TABLE]
این نتایج تست برنامه ی شما بود. برنامه تون با اعداد بزرگ مشکل داره.
#include<iostream.h>
#include<fstream.h>
int Dec(char ch)
{
char Roman[9]="XLCDIMV0";
int Decimal[8]={10,50,100,500,1,1000,5,0};
for(int i=0;i<7;i++)
if(ch==Roman[i])
return Decimal[i];
}
int main()
{
ifstream read("input.txt");
ofstream write("output.txt");
char s[1000];
long int Decimal=0,i;
read>>s;
for(i=strlen(s)-1;i>=0;i-=2)
{
if(i==0)
{
if(Dec(s[i])>=Dec(s[i+1]))
Decimal+=Dec(s[i]);
else
Decimal-=Dec(s[i]);
}
else
{
if(Dec(s[i])>Dec(s[i-1]))
Decimal+=Dec(s[i])-Dec(s[i-1]);
else
Decimal+=Dec(s[i])+Dec(s[i-1]);
}
}
write<<Decimal;
return 1374;
}