Created
October 1, 2019 06:30
-
-
Save resetius/9e8eef17c45df4728197a338c7f70c0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int perevod(char *s) | |
{ | |
int code[256]; | |
int i = 0; | |
int N = 0; | |
for (i = 0;i < 256; i ++) { | |
code[i] = 0; | |
} | |
code['X'] = 10; | |
code['I'] = 1; | |
code['V'] = 5; | |
code['L'] = 50; | |
code['C'] = 100; | |
while(*s != 0) { | |
if ((*s == 'I') && ((*(s + 1) = 'X') || (*(s + 1) == 'V'))) { | |
N = N + (code[*(s + 1)] - code[*s]); | |
s = s + 2; | |
} else { | |
N = N + code[*s]; | |
s = s + 1; | |
} | |
} | |
return(N); | |
} | |
int main() | |
{ | |
char ch[50]; | |
int N; | |
scanf("%s", ch); | |
printf("chislo = %s\n", ch); | |
N = perevod(ch); | |
printf("%d",N); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment