Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace Gistograma
- {
- class Program
- {
- static int Max(int[] array)
- {
- var max = array.Max();
- return max;
- }
- static int Min(int[] array)
- {
- var min = array.Min();
- return min;
- }
- static void PrintOutputArray(int numberOfNums, string[,] arrayOutput)
- {
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < numberOfNums + 7; j++)
- {
- Console.Write(arrayOutput[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void MakeGistogramm(int[] numsArray, ref string[,] arrayOutput, string f)
- {
- int pos = 6;
- for (int i = 0; i < numsArray.Length; i++)
- {
- pos++;
- int x = 0;
- int j = 9;
- while (x < numsArray[i])
- {
- x++;
- arrayOutput[j, pos] = f;
- j--;
- }
- }
- }
- static void Adduction(ref int[] numsArray, double[] doubleArray, double c)
- {
- for (int i = 0; i < doubleArray.Length; i++)
- {
- numsArray[i] = (int)(doubleArray[i] * c + 0.5);
- }
- }
- static void CheckArrayOfNums(ref int[] arrayNums, int numberOfNums)
- {
- for(int i = 0; i < numberOfNums; i++)
- {
- while (arrayNums[i] > 1024 || arrayNums[i] <= 0)
- {
- Console.WriteLine("Enter new num, the old one {0} is incorrect", arrayNums[i]);
- string str = Console.ReadLine();
- while (!int.TryParse(str, out int N))
- {
- Console.WriteLine("Enter new num, the old one {0} is incorrect", arrayNums[i]);
- str = Console.ReadLine();
- }
- arrayNums[i] = int.Parse(str);
- }
- }
- }
- static void PrintIntArray(int[] arrayChar)
- {
- for (int i = 0; i < arrayChar.Length; i++)
- {
- Console.WriteLine(arrayChar[i]);
- Console.WriteLine();
- }
- }
- static void PrintCharArray(char[] arrayChar)
- {
- for (int i = 0; i < arrayChar.Length; i++)
- {
- Console.WriteLine(arrayChar[i]);
- }
- }
- static void ArrayCharCheckAndFix(char[] arrayChar)
- {
- for (int i = 0; i < arrayChar.Length; i++)
- {
- if (arrayChar[i] == '0' || arrayChar[i] == '1' || arrayChar[i] == '2' || arrayChar[i] == '3' || arrayChar[i] == '4' || arrayChar[i] == '5' || arrayChar[i] == '6' || arrayChar[i] == '7' || arrayChar[i] == '8' || arrayChar[i] == '9' || arrayChar[i] == ' ')
- {
- }
- else
- {
- Console.WriteLine("{0} is incorrect", i);
- Console.WriteLine("Enter new element {0}", i);
- string s = Console.ReadLine();
- while (!int.TryParse(s, out int N) || N >= 9 || N < 0)
- {
- s = Console.ReadLine();
- }
- arrayChar[i] = Convert.ToChar(s);
- }
- }
- }
- static void Main(string[] args)
- {
- do
- {
- int counterOfLength = 0;
- int counterOfNums = 0;
- int[] numsArray = new int[120];
- int[] arrayNums = new int[120];
- string s = "";
- int pos = 0;
- int numberOfNums = 0;
- Console.WriteLine("Input");
- //input
- string inputString = Console.ReadLine() + " ";
- char[] arrayChar = inputString.ToCharArray();
- Console.WriteLine("Enter symbol");
- string f = Console.ReadLine();
- ArrayCharCheckAndFix(arrayChar);
- PrintCharArray(arrayChar);
- //searching for numbers in the input string
- for (int i = 0; i < arrayChar.Length; i++)
- {
- string str = Convert.ToString(arrayChar[i]);
- if (!int.TryParse(str, out int N))
- {
- try
- {
- if (int.TryParse(s, out int a))
- {
- arrayNums[pos] = int.Parse(s);
- }
- }
- catch(System.IndexOutOfRangeException)
- {
- Console.WriteLine("Too many numbers");
- Console.ReadLine();
- return;
- }
- pos++;
- s = "";
- numberOfNums++;
- }
- else
- {
- s = s + arrayChar[i];
- }
- }
- CheckArrayOfNums(ref arrayNums, numberOfNums);
- int[] array = new int[numberOfNums];
- for (int i = 0; i < numberOfNums; i++)
- {
- array[i] = arrayNums[i];
- }
- string minNum = Convert.ToString(Min(array));
- int max = arrayNums.Max(); // max * x = 10
- double c = 10 / (double)max;
- double[] doubleArray = new double[numberOfNums];
- for (int i = 0; i < numberOfNums; i++)
- {
- doubleArray[i] = (double)arrayNums[i];
- }
- Adduction(ref numsArray, doubleArray, c);
- //creating an array for output
- string[,] arrayOutput = new string[10, 126];//+7
- //filling the array with " "
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < numberOfNums + 10; j++)
- {
- arrayOutput[i, j] = " ";
- }
- }
- //setting some start setting for an array
- string maxNum = Convert.ToString(Max(arrayNums));
- for (int i = 0; i < maxNum.Length; i++)
- {
- arrayOutput[0, i + 1] = Convert.ToString(maxNum[i]);
- }
- for (int i = 0; i < minNum.Length; i++)
- {
- arrayOutput[9, i + 1] = Convert.ToString(minNum[i]);
- }
- //printing the line with "|" symbols
- for (int i = 0; i < 10; i++)
- {
- arrayOutput[i, 6] = "|";
- }
- MakeGistogramm(numsArray, ref arrayOutput, f);
- PrintOutputArray(numberOfNums, arrayOutput);
- try
- {
- using (StreamWriter sw = new StreamWriter("text.txt", true))
- {
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < numberOfNums + 7; j++)
- {
- sw.Write(arrayOutput[i, j]);
- }
- sw.WriteLine();
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- Console.WriteLine();
- } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement