Skip to content

Instantly share code, notes, and snippets.

@resetius
Created October 1, 2019 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save resetius/9e8eef17c45df4728197a338c7f70c0c to your computer and use it in GitHub Desktop.
Save resetius/9e8eef17c45df4728197a338c7f70c0c to your computer and use it in GitHub Desktop.
#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