JasperHuyghe

Lagenmodel oef8

Mar 10th, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. program.cs
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ExperimentAlgoritme
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Aantalruns a1 = new Aantalruns();
  15.  
  16.             Console.WriteLine("Geef de meting in");
  17.             Console.WriteLine(a1.Berekenen(Console.ReadLine()));
  18.             Console.ReadLine();
  19.         }
  20.     }
  21. }
  22.  
  23. Aantalruns.cs
  24. using System;
  25. using System.Collections.Generic;
  26. using System.Linq;
  27. using System.Text;
  28. using System.Threading.Tasks;
  29.  
  30. namespace ExperimentAlgoritme
  31. {
  32.     class Aantalruns
  33.     {
  34.         public string Berekenen(string input)
  35.         {
  36.             //string getallen = String.Concat(meting.Where(c => !Char.IsWhiteSpace(c)));
  37.             string[] metingen = input.Split(' ');
  38.             int runs = 0;
  39.             int currentRun = 1;
  40.             int previousMeting = int.Parse(metingen[0]); // Parse doet het converteren van string naar integer
  41.             for (int i = 1; i < metingen.Length; i++)
  42.             {
  43.                 int currentMeting = int.Parse(metingen[i]);
  44.                 if (currentMeting == -1)
  45.                 {
  46.                     break;
  47.                 }
  48.                 if (currentMeting > previousMeting)
  49.                 {
  50.                     currentRun++;
  51.                 }
  52.                 else
  53.                 {
  54.                     if (currentRun > 1)
  55.                     {
  56.                         runs++;
  57.                     }
  58.                     currentRun = 1;
  59.                 }
  60.                 previousMeting = currentMeting;
  61.             }
  62.             if (currentRun > 1)
  63.             {
  64.                 runs++;
  65.             }
  66.             return $"Aantal runs: {runs}";
  67.         }
  68.     }
  69. }
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment