Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ExperimentAlgoritme
- {
- class Program
- {
- static void Main(string[] args)
- {
- Aantalruns a1 = new Aantalruns();
- Console.WriteLine("Geef de meting in");
- Console.WriteLine(a1.Berekenen(Console.ReadLine()));
- Console.ReadLine();
- }
- }
- }
- Aantalruns.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ExperimentAlgoritme
- {
- class Aantalruns
- {
- public string Berekenen(string input)
- {
- //string getallen = String.Concat(meting.Where(c => !Char.IsWhiteSpace(c)));
- string[] metingen = input.Split(' ');
- int runs = 0;
- int currentRun = 1;
- int previousMeting = int.Parse(metingen[0]); // Parse doet het converteren van string naar integer
- for (int i = 1; i < metingen.Length; i++)
- {
- int currentMeting = int.Parse(metingen[i]);
- if (currentMeting == -1)
- {
- break;
- }
- if (currentMeting > previousMeting)
- {
- currentRun++;
- }
- else
- {
- if (currentRun > 1)
- {
- runs++;
- }
- currentRun = 1;
- }
- previousMeting = currentMeting;
- }
- if (currentRun > 1)
- {
- runs++;
- }
- return $"Aantal runs: {runs}";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment