Перевод из римского в арабское:
| Код | int Lexeme::CheckNumber(CString str) { BOOL X=FALSE, I=FALSE, V=FALSE, X1=FALSE; int num=0, countX=0, countI=0; for(int i=0;i<str.GetLength();i++) { if(X1) return -1; if(str[i]=='I') { if(I) return -1; if(countI<3) num++; else return -1; if(countX>0) X=TRUE; countI++; } if(str[i]=='V') { if((V)||(countI>1)) return -1; if(countI==1) { num+=3; I=TRUE; } else num+=5; if(countX>0) X=TRUE; V=TRUE; } if(str[i]=='X') { if((V)||(countI>1)) return -1; if(X) X1=TRUE; if(countI==1) { num+=8; I=TRUE; } else num+=10; if(countX>2) return -1; countX++; } } return num; }
| |