-3
私はこのプログラムを解決しようとしましたが、その間に詰まっていました。 この操作を実行するために、このコードをより価値のあるものにする必要があります。 ありがとうございます。2つのローマ数字を入力してC#を使用して3番目の数学演算を実行する方法は?
ここに私のコードです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MS_Test
{
class Program
{
static Rule[] Rules = new Rule[]
{
new Rule(1000, "M"),
new Rule(900, "CM"),
new Rule(500, "D"),
new Rule(400, "CD"),
new Rule(100, "C"),
new Rule(90, "XC"),
new Rule(50, "L"),
new Rule(40, "XL"),
new Rule(10, "X"),
new Rule(9, "IX"),
new Rule(5, "V"),
new Rule(4, "IV"),
new Rule(1, "I"),
};
static void Main(string[] args)
{
// Let the user convert numbers until they close the program
Console.WriteLine("Enter a positive integer:");
int n1;
if (Int32.TryParse(Console.ReadLine(), out n1) && n1 > 0)
Console.WriteLine("{0} in roman numerals is: {1}", n1, Romanise(n1)); // Write out the result
else
Console.WriteLine("That's not a positive integer");
Console.WriteLine("Enter another positive integer:");
int n2;
if (Int32.TryParse(Console.ReadLine(), out n2) && n2 > 0)
Console.WriteLine("{0} in roman numerals is: {1}", n2, Romanise(n2)); // Write out the result
else
Console.WriteLine("That's not a positive integer");
Console.ReadLine();
}
private static string Romanise(int n)
{
if (n == 0) return ""; // Recursion termination
foreach (var rule in Rules) // Rules are in descending order
if (rule.N <= n)
return rule.Symbol + Romanise(n - rule.N); // Recurse
// If this line is reached then n < 0
throw new ArgumentOutOfRangeException("n must be greater than or equal to 0");
}
// Represents a substitution rule for a roman-numerals like numerical system
// Number 'N' is equivilant to string 'Symbol' in the system.
class Rule
{
public int N { get; set; }
public string Symbol { get; set; }
public Rule(int n, string symbol)
{
N = n;
Symbol = symbol;
}
}
}
}
皆さんからの貴重な回答を楽しみにしています。
あなたは
これは私が「モーラvalnurable」このコードを作成する方法を知っている...も行いませんhttp://stackoverflow.com/questions/7040289/converting-integers-to-roman-numerals – user6594294
役立つかもしれません"mora valnurable"という用語は理解できない英語であるため、誰でもあなたの質問を改訂してください。 – spender
@Qadeerこれも試しました。しかし、新生児が適切にそれを得ることができないように。これであなたが私を助けることは可能でしょうか? –