Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void task3() {
- std::string roman;
- int arabic = 0;
- std::cin >> roman;
- bool check = true;
- while (std::cin >> roman) {
- for (int i = 0; i < roman.length(); i++) {
- if (roman[i] == 'I' || roman[i] == 'V' || roman[i] == 'X' || roman[i] == 'L' ||
- roman[i] == 'C' || roman[i] == 'D' || roman[i] == 'M') {
- check = true;
- }
- else {
- std::cout << "Wrong input data." << std::endl;
- std::exit(0);
- }
- }
- }
- int current_value = 0;
- bool order = false;
- for (int i = 0; i < roman.length(); i++) {
- if (roman[i] == 'C' && roman[i+1] == 'M' || roman[i] == 'C' && roman[i+1] == 'M' || roman[i] == 'C' && roman[i+1] == 'M' || ) {
- order = false;
- break;
- }
- if (roman[i] == 'C' && roman[i+1] == 'M') {
- current_value += 900;
- }
- else if (roman[i] == 'C' && roman[i+1] == 'D') {
- current_value += 400;
- }
- else if (roman[i] == 'X' && roman[i+1] == 'C') {
- current_value += 90;
- }
- else if (roman[i] == 'X' && roman[i+1] == 'L') {
- current_value += 40;
- }
- else if (roman[i] == 'I' && roman[i+1] == 'X') {
- current_value += 9;
- }
- else if (roman[i] == 'I' && roman[i+1] == 'V') {
- current_value += 4;
- }
- else if(roman[i] == 'M') {
- current_value += 1000;
- }
- else if (roman[i] == 'D') {
- current_value += 500;
- }
- else if (roman[i] == 'C') {
- current_value += 100;
- }
- else if (roman[i] == 'L') {
- current_value += 50;
- }
- else if (roman[i] == 'X') {
- current_value += 10;
- }
- else if (roman[i] == 'V') {
- current_value += 5;
- }
- else if (roman[i] == 'I') {
- current_value += 1;
- }
- }
- arabic = current_value;
- if (/*order == false || */arabic < 1 || arabic > 3999) {
- std::cout << "Wrong input data." << std::endl;
- }
- else {
- std::cout << "Converted " << roman << "to " << arabic << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement