Advertisement
Guest User

C# Basics Exam 12 April 2014 Morning - 2. Pairs

a guest
Aug 20th, 2014
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 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 ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string sequence = Console.ReadLine();
  14.             string[] array = sequence.Split(' ');
  15.             List<int> sum = new List<int>();
  16.              for (int i = 0; i < (array.Length); i += 2)
  17.                 {
  18.             int x = Convert.ToInt32(array[i]);
  19.                         int y = Convert.ToInt32(array[i + 1]);
  20.                         int sumXandY = x + y;
  21.                         sum.Add(sumXandY);
  22.                 }
  23.  
  24.                 int max = sum.Max();
  25.                 if (max == (sum.Min()))
  26.                 {
  27.                     Console.WriteLine("Yes, value=" + sum[0]);
  28.                 }
  29.                 else
  30.                 {
  31.                     Console.WriteLine("No, maxdiff=" + (max - sum.Min()));
  32.                 }
  33.  
  34.             Console.ReadLine();
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement