Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <map>
- #include <Windows.h>
- using namespace std;
- bool e = false;
- void romanToInt() {
- char s[256];
- int total = 0, i;
- map<char, int> m = { {'I', 1}, {'V', 5},{'X', 10},{'L', 50},
- {'C', 100},{'D', 500},{'M', 1000} };
- printf("Введите число в РИМСКОЙ системе счисления (I, V, X, L, C, D, M): ");
- do {
- if (e) {
- printf("Ошибка. Повторите ввод: ");
- }
- e = false;
- gets_s(s, 256);
- for (i = 0; i < strlen(s); i++) {
- if (m[s[i + 1]] <= m[s[i]])
- total += m[s[i]];
- else total -= m[s[i]];
- }
- if (!total)
- e = true;;
- } while (e);
- printf("Число %s в десятичной системе счисления: %d", s, total);
- }
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- printf("Перевод из Римской системы счисления в десятичную.\n");
- romanToInt();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement