Advertisement
Guest User

Lesson 4- Bai 1

a guest
Apr 6th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 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.  
  7. namespace Bai1
  8. {
  9.     class Program
  10.     {
  11.        
  12.         static void Main(string[] args)
  13.         {
  14.             int n;
  15.             int[] a;
  16.             bool[] res;
  17.             n = int.Parse(Console.ReadLine());
  18.             a = new int[n];
  19.  
  20.             string[] temp = Console.ReadLine().Split();
  21.             for (int i = 0; i < n; i++)
  22.             {
  23.                 a[i] = int.Parse(temp[i]);
  24.             }
  25.             int maxTemp = findMax(a);
  26.            
  27.             res = new bool[maxTemp + 1];
  28.  
  29.             for (int i = 0; i < n; i++)
  30.             {
  31.                 res[a[i]] = true;
  32.             }
  33.  
  34.             for (int i = 1; i < res.Length; i++)
  35.             {
  36.                 if (!res[i]) {
  37.                     Console.WriteLine(i);
  38.                     break;
  39.                 }                
  40.             }
  41.         }
  42.  
  43.         static int findMax(int[] a)
  44.         {
  45.             int max = a[0];
  46.  
  47.             for (int i = 1; i < a.Length; i++)
  48.             {
  49.                 if (a[i] > max) max = a[i];
  50.             }
  51.             return max;
  52.         }
  53.  
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement