Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- namespace zad1
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Console.Write("Write the directory of the wanted .txt file: ");
- // string txtFile="";
- Console.Write("Write the directory of the wanted .txt file: ");
- string input = Console.ReadLine();
- string txt = File.ReadAllText($@"{input}");
- int counter = 0;
- foreach (var ch in txt.Split(","))
- {
- counter++;
- }
- int[] numarr = new int[counter];
- ReadArrayFromFile(numarr,txt);
- Console.WriteLine();
- ReverseInPlace(numarr);
- Console.WriteLine();
- MostCommonCount(numarr);
- // string txtFile = File.ReadAllText($@"{input}");
- //E:\Tekst.txt
- }
- public static void ReadArrayFromFile(int[] numarr, string txtFile)
- {
- int i = 0;
- foreach (var ch in txtFile.Split(","))
- {
- numarr[i] = int.Parse(ch);
- i++;
- }
- foreach (var num in numarr)
- {
- Console.Write(num + " ");
- }
- }
- public static void ReverseInPlace(int[] numarr)
- {
- for (int i = 0; i<numarr.Length/2; i++)
- {
- int curr = numarr[i];
- numarr[i] = numarr[numarr.Length - 1 - i];
- numarr[numarr.Length - i - 1] = curr;
- }
- foreach (var item in numarr)
- {
- Console.Write(item+" ");
- }
- }
- public static void MostCommonCount (int[] numarr)
- {
- int commonNum=0;
- int count = 0;
- for (int i = 0; i < numarr.Length; i++)
- {
- int currcount=0;
- int number = numarr[i];
- foreach (var num in numarr)
- {
- if (num == number)
- {
- currcount++;
- }
- }
- if (currcount > count)
- {
- count = currcount;
- commonNum = number;
- }
- }
- Console.WriteLine($"{commonNum} is contained {count} times!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement