Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main() {
- char input[10];
- char rimDigits[] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
- int c, index, i, sum = 0, arabDigits[] = {1, 5, 10, 50, 100, 500, 1000};
- cout << "4.6: Введите римское число: " << endl;
- cin >> input;
- c = strlen(input);
- if (c >= 4) {
- if (input[c - 1] == input[c - 2] && input[c - 3] && input[c - 4]) {
- printf("Ошибка в написании!\n");
- return 0;
- }
- }
- i = c - 1;
- for (int j = 0; j < 7; j++) {
- if (input[i] == rimDigits[j]) {
- index = j;
- sum = arabDigits[j];
- }
- }
- for (i = i - 1; i >= 0; i--) {
- for (int j = 0; j < 7; j++) {
- if (input[i] == rimDigits[j])
- if (j >= index) {
- sum += arabDigits[j];
- index = j;
- }
- else if (j < index) {
- sum -= arabDigits[j];
- index = j;
- }
- }
- }
- printf("Число = %d\n", sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement