ApplesOrOranges


SUBMITTED BY: Guest

DATE: Dec. 7, 2013, 5:14 p.m.

FORMAT: Text only

SIZE: 1.6 kB

HITS: 51994

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. checked
  12. {
  13. long n = long.Parse(Console.ReadLine());
  14. if (n < 0)
  15. {
  16. n *= (-1);
  17. }
  18. long evenSum = 0;
  19. long oddSum = 0;
  20. long currentNumber = n;
  21. for (int i = 0; i < n; i++)
  22. {
  23. long currentDigit = 0;
  24. long num = currentNumber;
  25. currentDigit = currentNumber % 10;
  26. currentNumber = currentNumber / 10;
  27. if (currentDigit % 2 == 0)
  28. {
  29. evenSum += currentDigit;
  30. }
  31. else if (currentDigit % 2 == 1)
  32. {
  33. oddSum += currentDigit;
  34. }
  35. if (currentNumber<10 && currentDigit<=0)
  36. {
  37. break;
  38. }
  39. }
  40. if (evenSum == oddSum)
  41. {
  42. Console.WriteLine("both {0}", evenSum);
  43. }
  44. else if (evenSum > oddSum)
  45. {
  46. Console.WriteLine("apples {0}", evenSum);
  47. }
  48. else if (evenSum < oddSum)
  49. {
  50. Console.WriteLine("oranges {0}", oddSum);
  51. }
  52. }
  53. }
  54. }

comments powered by Disqus