Advertisement
stefan1919

Pairs

Aug 25th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 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 ConsoleApplication4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string inputWithSpaces = Console.ReadLine();
  14.             int[] numbers = inputWithSpaces.Split(' ').Select(int.Parse).ToArray();
  15.             int sum = 0;
  16.             int counter = 0;
  17.             int checkerArray = 0;
  18.             int[] sums = new int[numbers.Length / 2];
  19.             for (int i = 0; i < numbers.Length; i++)
  20.             {
  21.                 if (i % 2 == 0)
  22.                 {
  23.                      sum += numbers[i];
  24.                 }
  25.                 if (i % 2 == 1)
  26.                 {
  27.                     sum += numbers[i];
  28.                     sums[checkerArray] = sum;
  29.                     checkerArray++;
  30.                     sum = 0;
  31.                     counter++;
  32.                 }
  33.             }
  34.             int x = 0;
  35.             int checker = 0;
  36.             int max = int.MinValue;
  37.             int min = sums[0];
  38.             for (int j = 0; j < counter; j++)
  39.             {
  40.                 checker = sums[0];
  41.                 if (sums[j] > max)
  42.                 {
  43.                     max = sums[j];
  44.                 }
  45.                 if (sums[j] < min)
  46.                 {
  47.                     min = sums[j];
  48.                 }
  49.                 if (sums[j] != checker)
  50.                 {
  51.                     x = 1;
  52.                 }
  53.             }
  54.             int p = Math.Abs(max - min);
  55.             if (x == 0)
  56.             {
  57.                 Console.WriteLine("{0}{1}", "Yes, value=", checker);
  58.             }
  59.             if (x == 1)
  60.             {
  61.                 Console.WriteLine("{0}{1}", "No, maxdiff=", p);
  62.             }
  63.                
  64.            
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement