#include #include using namespace std; int fromroman(string s) { if (s[0]=='O') return 0; int pom=0; int suc=0; for (int i=0;i0 && (ss[i]-'0')<10) if (!bregs[ss[i]-'0']) { printf("Error\n"); continue; } } int temp=0; string stmp=""; bool plus=true; for (int i=2;ss[i]!='\n';i++) { if ((ss[i]-'0')>0 && (ss[i]-'0')<10) { if (plus) { temp+=regs[ss[i]-'0']; } else temp-=regs[ss[i]-'0']; continue; } if (ss[i]=='+') { if (stmp!="") { if (plus) { temp+=fromroman(stmp); } else temp-=fromroman(stmp); } plus=true; stmp=""; continue; } if (ss[i]=='-') { if (stmp!="") { if (plus) { temp+=fromroman(stmp); } else temp-=fromroman(stmp); } plus=false; stmp=""; continue; } stmp+=ss[i]; } if (stmp!="") { if (plus) { temp+=fromroman(stmp); } else temp-=fromroman(stmp); } if (temp<0 || temp>10000) { printf("Error\n"); continue; } regs[toreg]=temp; bregs[toreg]=true; printf("%d=%s\n",toreg,toroman(regs[toreg]).c_str()); } return 0; }