#1
15.10.2018 um 13:51 Uhrdas ist nicht Aufgabe 198
falsche Zuordnung
falsche Zuordnung
C# :: Aufgabe #198 :: Lösung #3
using System;
using System.Collections.Generic;
namespace Aufgabe176
{
class Program
{
static void Main(string[] args)
{
List<List<int>> array = new List<List<int>>();
List<int> pre_array = new List<int>();
Int32 n;
while (true)
{
try
{
Console.Write("Zahl eingeben: ");
string eing = Console.ReadLine();
Int32.TryParse(eing, out n);
break;
}
catch
{
Console.WriteLine("Keine Zahl eingegeben! Bitte nochmal!\n");
}
}
Int32 i = 1;
Int32 j = 1;
Int32 k = 0;
while (true)
{
if (i < n)
{
while (i < n)
{
pre_array.Add(i);
i += k + j;
k += 1;
}
}
else if (i == n)
{
pre_array.Add(i);
array.Add(pre_array);
break;
}
else
{
List<int> c_array = new List<int>(pre_array);
array.Add(c_array);
i = array[j - 1][0] + j + 1;
j += 1;
k = 0;
pre_array.Clear();
}
}
for(int l = 0; l < array.Count; l++)
{
if (array[l].Contains(n))
{
Console.WriteLine("ZN = " + l + ", SN = " + array[l].IndexOf(n));
}
}
}
}
}
Kommentare:
hollst
Punkte: 13980
761 Aufgaben
132 Lösungen
117 Kommentare