📄 3309266_ac_16ms_216k.c
字号:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int get(char p[],char t[])
{
int i, j;
for(i = 0; t[i]; i++)
{
if(p[0]==t[i])
{
for(j = i+1; t[j]; j++)
{
if(p[1]==t[j])
return j;
}
}
}
return -1;
}
int main()
{
char str[10001];
char tmp[10001];
int i, len, max, pos, cnt;
while(gets(str)!=NULL)
{
len = 0;
for(i = 0; str[i]; i++)
{
if(str[i]=='i'||str[i]=='v'||str[i]=='x'||str[i]=='l'||str[i]=='c'||str[i]=='d'||str[i]=='m')
{
tmp[len++] = str[i];
}
}
tmp[len] = 0;
max = 0;pos = 0;
for(i = 0; i < len; i++)
{
if(tmp[i]=='m')
{
max += 1000;
pos = i;
}
}
for(i = pos; i < len; i++)
{
if(tmp[i]=='d')
{
max += 500;
pos = i;
break;
}
}
for(i = pos,cnt = 3; cnt > 0&&i < len; i++)
{
if(tmp[i]=='c')
{
max += 100;
pos = i;
cnt--;
}
}
if(get("xc",&tmp[pos+1])!=-1)
{
max += 90;
pos += get("xc",&tmp[pos+1]);
}
else
{
for(i = pos; i < len; i++)
{
if(tmp[i]=='l')
{
max += 50;
pos = i;
break;
}
}
for(i = pos,cnt = 3; cnt > 0&&i < len; i++)
{
if(tmp[i]=='x')
{
max += 10;
pos = i;
cnt--;
}
}
}
if(get("ix",&tmp[pos+1])!=-1)
{
max += 9;
pos += get("ix",&tmp[pos+1]);
}
else
{
for(i = pos; i < len; i++)
{
if(tmp[i]=='v')
{
max += 5;
pos = i;
break;
}
}
for(i = pos,cnt = 3; cnt > 0&&i < len; i++)
{
if(tmp[i]=='i')
{
max ++;
pos = i;
cnt--;
}
}
}
printf("%d\n",max);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -