Guest User

Untitled

a guest
Jul 15th, 2019
1,024
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Find_Largest_Three_Values_2
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.             int firstNum = int.MinValue;
  12.             int secondNum = int.MinValue;
  13.             int thirdNum = int.MinValue;
  14.  
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.                 int currentNum = int.Parse(Console.ReadLine());
  18.  
  19.                 if (currentNum > firstNum)
  20.                 {
  21.                     thirdNum = secondNum;
  22.                     secondNum = firstNum;
  23.                     firstNum = currentNum;
  24.                 }
  25.                 else if (currentNum > secondNum)
  26.                 {
  27.                     thirdNum = secondNum;
  28.                     secondNum = currentNum;
  29.  
  30.                 }
  31.                 else if (currentNum > thirdNum)
  32.                 {
  33.                     thirdNum = currentNum;
  34.                 }
  35.             }
  36.             Console.WriteLine($"{firstNum}, {secondNum} and {thirdNum}");
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment