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