罗马数字转阿拉伯数字

1.罗马数字是位置计数吗?有什么缺点?
罗马数字不是位置计数,对于位置没有同等含义
无论是书写,还是读数,都不如阿拉伯数字简单直观,一目了然且不能直接用于加减乘除运算。
2.学号转化
元学号:20221418 转化后:MMXXII MCCCCXVIII
3.罗马数字程序实现
注:由于本人对于C语言的掌握程度较低,所以借鉴了一下其他同学的作业,希望老师理解。

include "stdafx.h"

include<stdio.h>

int GetNumber(const char* strNum)
{
int nValue = 0;
while(*strNum != '\0')
{
int nN = 0;
char c = (strNum+1);
switch(
strNum)
{
case 'I':
nN = ((c != 'V' && c!= 'X') ? 1 : -1);
break;
case 'V':
nN = 5;
break;
case 'X':
nN = ((c != 'L' && c != 'C') ? 10 : -10);
break;
case 'L':
nN = 50;
break;
case 'C':
nN = ((c != 'D' && c != 'M') ? 100 : -100);
break;
case 'D':
nN = 500;
break;
case 'M':
nN = 1000;
break;
}
nValue += nN;
++strNum;
}
return nValue;
}
注:下面是本人打的代码,但是不知道下一步怎么运行了,就是不知道如何将两者相乘。

define _CRT_SECURE_NO_WARNINGS

include <stdio.h>

define LEN 26

int main()
{
int M,D,C,L,X,V,I;
M = 1000;
D = 500;
C = 100;
L = 50;
X = 10;
V = 5;
I = 1;
int letter[LEN] = { 0 },i;
char ch;
printf("请输入罗马数字:\n");
while ((ch=getchar())!='\n')
{
if (ch >= 'A'&&ch <= 'Z')
letter[ch - 'A'] = letter[ch - 'A'] + 1;
}
printf("每一个字母出现的次数\n");
for (i=0;i<LEN;i++)
{
printf("%c:%-4d",'a'+i,letter[i]);
if ((i+1)%13==0) printf("\n");
}
return 0;
}

posted @ 2022-09-17 22:01  20221418曾庆林  阅读(21)  评论(0编辑  收藏  举报