#1
23.04.2021 um 19:35 UhrDie Lösung entspricht leider keiner der o.a. Aufgabenstellungen.
C# :: Aufgabe #352 :: Lösung #1
using System;
using System.Collections.Generic;
namespace TJP352_Zahlenpaare
{
class Program
{
static void Main(string[] args)
{
// Testliste befüllen
List<int> myList = new List<int>();
for(int i=1; i<=20; i++)
{
for (int j = 0; j < i; j++)
{
myList.Add(i);
}
}
FindeZahlenpaare(myList);
}
/// <summary>
/// Zahlenpaare finden
/// </summary>
private static void FindeZahlenpaare(List<int> myList)
{
var itemList = new List<int>();
var ergebnis = new List<KeyValuePair<int, int>>();
// Zahlenpaare ermitteln
foreach (var item in myList)
{
if (!itemList.Contains(item))
{
itemList.Add(item);
int anzahl = myList.FindAll(x => x.Equals(item)).Count;
ergebnis.Add(new KeyValuePair<int, int>(item, (int)(item * BerechneMultiplikator(anzahl))));
}
}
// Ausgabe
foreach (var item in ergebnis)
{
Console.WriteLine("Zahlepaare für {0}: {1}", item.Key, item.Value);
}
}
/// <summary>
/// Multiplikator berechnen
/// </summary>
private static float BerechneMultiplikator(int anzahl)
{
// Formel: 1 + (anzahl - 3) * 0.5
return 1 + (anzahl - 3) * 0.5f;
}
}
}
Kommentare:
JKooP
Punkte: 18090
680 Aufgaben
227 Lösungen
19 Kommentare