Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int rim_dek (string a)
- {
- a = a + " ";
- string k = "";
- int s = 0;
- for (int i=0; i<a.length()-1; i++)
- {
- k = k + a[i];
- k = k + a[i+1];
- if (k=="IV")
- {s = s + 4; i++;}
- else if (k=="IX")
- {s = s + 9; i++;}
- else if (k=="XL")
- {s = s + 40; i++;}
- else if (k=="XC")
- {s = s + 90; i++;}
- else if (k=="CD")
- {s = s + 400; i++;}
- else if (k=="CM")
- {s = s + 900; i++;}
- else if (k=="IM")
- {s = s + 999; i++;}
- else if (k=="XM")
- {s = s + 990; i++;}
- else
- {
- switch (a[i])
- {
- case 'I': s = s + 1; break;
- case 'V': s = s + 5; break;
- case 'X': s = s + 10; break;
- case 'L': s = s + 50; break;
- case 'C': s = s + 100; break;
- case 'D': s = s + 500; break;
- case 'M': s = s + 1000; break;
- }
- }
- k="";
- }
- return s;
- }
- string dek_rim (int a)
- {
- string s = "";
- while (a>=1000) { s = s + "M"; a = a - 1000; }
- while (a>=999) { s = s + "IM"; a = a - 999; }
- while (a>=990) { s = s + "XM"; a = a - 990; }
- while (a>=900) { s = s + "CM"; a = a - 900; }
- while (a>=500) { s = s + "D"; a = a - 500; }
- while (a>=400) { s = s + "CD"; a = a - 400; }
- while (a>=100) { s = s + "C"; a = a - 100; }
- while (a>=90) { s = s + "XC"; a = a - 90; }
- while (a>=50) { s = s + "L"; a = a - 50; }
- while (a>=40) { s = s + "XL"; a = a - 40; }
- while (a>=10) { s = s + "X"; a = a - 10; }
- while (a>=9) { s = s + "IX"; a = a - 9; }
- while (a>=5) { s = s + "V"; a = a - 5; }
- while (a>=4) { s = s + "IV"; a = a - 4; }
- while (a>=1) { s = s + "I"; a = a - 1; }
- return s;
- }
- main()
- {
- int n;
- string s[101];
- cin >> n;
- for (int i=1; i<=n; i++)
- cin >> s[i];
- if (n%2==1)
- n = n - 1;
- for (int i=1; i<=n; i=i+2)
- {
- int a = rim_dek(s[i]) + rim_dek(s[i+1]);
- if (a<3999)
- cout << dek_rim(a) << endl;
- else
- cout << "Prekoracenje" << endl;
- }
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement