#include #include using namespace std; char line[10000]; //zpracovany radek vstupu string out; int registers [10]; //registry void reset(){ for(int i=0; i<10; i++) registers[i]=-1; cout << "Ready" << endl; } void error(){ cout<<"Error"<='0'&&znak<='9'){ //je to cislo cout << "operand je registr " << line[i] << endl; operand=registers[znak-'0']; //cout<10000) error(); else registers[regDest]=tempVysledek; //cout<='A' && line[i]<='Z'){ // cout << "switch " << endl; switch (line[i]){ case 'M': operand+=1000;break; case 'D': operand+=500;break; case 'C': { switch (line[i+1]){ case 'D':operand+=400;i++; break; case 'M':operand+=900;i++; break; default:operand+=100; } };break; case 'L': operand+=50;break; case 'X': { switch (line[i+1]){ case 'L':operand+=40;i++; break; case 'C':operand+=90;i++; break; default:operand+=10; } };break; case 'V': operand+=5;break; case 'I': { switch (line[i+1]){ case 'V':operand+=4;i++; break; case 'X':operand+=9;i++; break; default:operand+=1; } };break; case 'O':break; } //end top case i++; } i--; //cout << "RIM: " << operand << endl; return operand; } void vypisRim(int c){ while(c>=1000){ out+='M'; c-=1000; } while(c>=900){ out+="CM"; c-=900; } while(c>=500){ out+='D'; c-=500; } while(c>=400){ out+="CD"; c-=400; } while(c>=100){ out+='C'; c-=100; } while(c>=90){ out+="XC"; c-=90; } while(c>=50){ out+='L'; c-=50; } while(c>=40){ out+="XL"; c-=40; } while(c>=10){ out+='X'; c-=10; } while(c>=9){ out+="IX"; c-=9; } while(c>=5){ out+='V'; c-=5; } while(c>=4){ out+="IV"; c-=4; } while(c>=1){ out+='I'; c-=1; } cout << out << endl; out = ""; } void processLine2() { if (line[0] == 'R') { reset(); return; } int i=0,val, temp; int dr=line[i]-'0'; char oper; x: i++; oper=line[i++]; if(line[i]>='0'&&line[i]<='9'){ int a = line[i]-'0'; val=registers[a]; if (val<0){ error(); return; } } else{ val=parseRim(i); } switch (oper){ case '+': temp += val; break; case '-': temp -= val;break; case '=': temp = val;break; } if (line[i+1]!='\0') goto x; if(temp<0||temp>10000) error(); else{ //cout << "hodnota " << temp << endl; registers[dr]=temp; cout << dr<<"="<