Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void rome2arab(string r) {
- int d = 0;
- int i = 0;
- while (i < r.length()) {
- //Обрабатываем исключения
- if (r[i] == 'C' && r[i+1] == 'M') {d += 900; i+=2; continue;}
- else if (r[i] == 'C' && r[i+1] == 'D') {d += 400; i+=2; continue;}
- else if (r[i] == 'X' && r[i+1] == 'C') {d += 90; i+=2; continue;}
- else if (r[i] == 'X' && r[i+1] == 'L') {d += 40; i+=2; continue;}
- else if (r[i] == 'I' && r[i+1] == 'X') {d += 9; i+=2; continue;}
- else if (r[i] == 'I' && r[i+1] == 'V') {d += 4; i+=2; continue;}
- //Если не попалось исключение, то просто прибавляем
- else if (r[i] == 'M') {d += 1000; i++}
- else if (r[i] == 'D') {d += 500; i++}
- else if (r[i] == 'C') {d += 100; i++}
- else if (r[i] == 'L') {d += 50; i++}
- else if (r[i] == 'X') {d += 10; i++}
- else if (r[i] == 'V') {d += 5; i++}
- else if (r[i] == 'I') {d += 1; i++}
- else cout << "Что-то тут не так..." << endl;
- }
- cout << d << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment