私は、組み合わせ方法を使用するコーディングを持っています。C#組み合わせの第1、第2、第3の回答のみを表示するには?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
string input;
int NoDisplay;
decimal goal;
decimal element;
do
{
Console.WriteLine("Please enter the target:");
input = Console.ReadLine();
}
while (!decimal.TryParse(input, out goal));
Console.WriteLine("Please enter the numbers (separated by spaces)");
input = Console.ReadLine();
string[] elementsText = input.Split(' ');
List<decimal> elementsList = new List<decimal>();
foreach (string elementText in elementsText)
{
if (decimal.TryParse(elementText, out element))
{
elementsList.Add(element);
}
}
int i;
int j;
decimal tmp;
int[] arr1 = new int[10];
for (i = 0; i < elementsList.Count; i++)
{
for (j = i + 1; j < elementsList.Count; j++)
{
if (elementsList[i] < elementsList[j])
{
tmp = elementsList[i];
elementsList[i] = elementsList[j];
elementsList[j] = tmp;
}
}
}
Console.WriteLine("Please enter the maximum combination :");
NoDisplay = Convert.ToInt32(Console.ReadLine());
Solver solver = new Solver();
List<List<decimal>> results = solver.Solve(goal, elementsList.ToArray());
//results.Reverse();
Boolean recordexist = false;
foreach (List<decimal> result in results)
{
if (result.Count == NoDisplay)
{
recordexist = true;
foreach (decimal value in result)
{
Console.Write("{0}\t", value);
}
if (recordexist == true)
{
Console.WriteLine();
}
}
}
if (recordexist == false)
{
Console.WriteLine("No record exist");
}
Console.ReadLine();
}
}
私の質問は、私は私の悪い英語のための唯一の Like this
申し訳ありませんが、第一、第二および第三の答えを表示することができますどのように、私は誰もがこれで私を助けることができると思います。私はまだc#btwで新しいです。ありがとうございます
あなたはここに自分自身を画像を追加することができます、または出力自体に貼り付けて対処してください。 Imgurのリンクはスパムとしてマークされる可能性があります。 – garg10may
大丈夫です。あなたのおかげでアドバイスをありがとう:) – Nobody