c#如何将罗马数字转换为数字[反之亦然]
c#如何将罗马数字转换为数字[反之亦然] 示例:I=1 V=5等 我不知道该用什么,条件,方法,循环等等。 代码我必须感谢。这应该对你有帮助:)c#如何将罗马数字转换为数字[反之亦然],c#,C#,c#如何将罗马数字转换为数字[反之亦然] 示例:I=1 V=5等 我不知道该用什么,条件,方法,循环等等。 代码我必须感谢。这应该对你有帮助:) static void Main(字符串[]args) { string roman=Console.ReadLine(); 整数十位数=0; int当前_指数=0; for(int i=0;i
static void Main(字符串[]args)
{
string roman=Console.ReadLine();
整数十位数=0;
int当前_指数=0;
for(int i=0;i
希望有帮助:)要求其他人为您编写代码的问题通常不太受欢迎。@PrinceTakieshima仅供参考,我否决了这个问题,因为它缺乏您解决问题的任何努力。但是您仍然可以使用条件语句,例如
if..else
或'switch..case'etc@PrinceTakieshima仅供参考,在queuein c#windows应用程序中对问题进行注释不会将其上移。只需将“Console.WriteLine(result)”替换为“tb.Text=result”,并使用其他minkr更改:)
static void Main(string[] args)
{
string roman = Console.ReadLine();
int tens = 0;
int current_index = 0;
for (int i = 0; i < roman.Length; i++)
{
if (roman[i] == 'X')
tens++;
else
{
current_index = i;
break;
}
}
int result = 0;
switch (roman.Substring(current_index))
{
case "I" :
result = (tens * 10) + 1;
break;
case "II" :
result = (tens * 10) + 2;
break;
case "III" :
result = (tens * 10) + 3;
break;
case "IV" :
result = (tens * 10) + 4;
break;
case "V" :
result = (tens * 10) + 5;
break;
case "VI" :
result = (tens * 10) + 6;
break;
case "VII" :
result = (tens * 10) + 7;
break;
case "VIII" :
result = (tens * 10) + 8;
break;
case "IX" :
result = (tens * 10) + 9;
break;
}
Console.WriteLine(result);
Console.ReadLine();
}