Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Security;
  8.  
  9. namespace ConsoleApp3
  10. {
  11.     class Program
  12.     {
  13.         static Random rnd = new Random();
  14.  
  15.         static public int Method(int a, int b)
  16.         {
  17.             return rnd.Next(a, b);
  18.         }
  19.         static void Main(string[] args)
  20.         {
  21.             // ReSharper, специфицированная обработка исключений, индексы в рандоме, LINQ в массивах, исключения в файлах
  22.  
  23.             string str = @"C:\n\input.txt";
  24.  
  25.             try
  26.             {
  27.                 Method(10, 5);
  28.             }
  29.             catch (ArgumentOutOfRangeException e)
  30.             {
  31.                 Console.WriteLine(e.Message);
  32.                 return;
  33.             }
  34.  
  35.             string[] fileStrings;
  36.             try
  37.             {
  38.                  fileStrings = File.ReadAllLines("../../input.txt");
  39.             }
  40.             catch (IOException e)
  41.             {
  42.                 Console.WriteLine(e.Message);
  43.                 return;
  44.             }
  45.  
  46.             int[] arr = new int[fileStrings.Length];
  47.  
  48.             try
  49.             {
  50.                 for (int i = 0; i < arr.Length; i++)
  51.                 {
  52.                     arr[i] = int.Parse(fileStrings[i]);
  53.  
  54.                     if (arr[i] < 10)
  55.                         throw new ArgumentException("<10.");
  56.                 }
  57.             }
  58.             catch (FormatException)
  59.             {
  60.                 Console.WriteLine("format.");
  61.                 return;
  62.             }
  63.             catch (OverflowException)
  64.             {
  65.                 Console.WriteLine("overflow.");
  66.                 return;
  67.             }
  68.             catch (ArgumentException ex)
  69.             {
  70.                 Console.WriteLine(ex.Message);
  71.                 return;
  72.             }
  73.  
  74.             int max = arr.Max();
  75.             try
  76.             {
  77.                 File.WriteAllText("../../output.txt", max.ToString());
  78.             }
  79.             catch (IOException e)
  80.             {
  81.                 Console.WriteLine(e.Message);
  82.                 return;
  83.             }
  84.             catch (Exception e)
  85.             {
  86.                 Console.WriteLine(e.Message);
  87.             }
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement