Advertisement
Guest User

Untitled

a guest
Dec 6th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 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 _02_ApplesAndOranges
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             //string input = "112";
  15.  
  16.             int sumOfEvenDigits = 0;
  17.             int sumOfOddDigits = 0;
  18.  
  19.             for (int i = 0; i < input.Length; i++)
  20.             {
  21.                 if ((int)Char.GetNumericValue(input[i]) % 2 == 1)
  22.                 {
  23.                     sumOfOddDigits += (int)Char.GetNumericValue(input[i]);
  24.                 }
  25.  
  26.                 else if ((int)Char.GetNumericValue(input[i]) % 2 == 0)
  27.                 {
  28.                     sumOfEvenDigits += (int)Char.GetNumericValue(input[i]);
  29.                 }
  30.             }
  31.  
  32.  
  33.             if (sumOfOddDigits > sumOfEvenDigits)
  34.             {
  35.                 Console.WriteLine("oranges " + sumOfOddDigits);
  36.             }
  37.  
  38.             else if (sumOfEvenDigits > sumOfOddDigits)
  39.             {
  40.                 Console.WriteLine("apples " + sumOfEvenDigits);
  41.             }
  42.  
  43.  
  44.             else if (sumOfOddDigits == sumOfEvenDigits)
  45.             {
  46.                 Console.WriteLine("both " + sumOfEvenDigits);
  47.             }
  48.  
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement