Categories
Visual C# Телерик

Задача: Nightmare On Code Street

Решение

using System;

namespace NightmareOnCodeStreet {
  class Program {
    static void Main() {
      string number = Console.ReadLine();
      char[] numbersList = number.ToCharArray();
      int size = numbersList.Length;
      if (numbersList[0] - '0' < 0) {
        for (int i = 0; i < numbersList.Length - 1; i++) {
          numbersList[i] = numbersList[i + 1];
        }
        size--;
      }
      int counter = 0;
      int sum = 0;
      for (int i = 0; i < size; i++) {
        if (i % 2 != 0) {
          if (Char.IsDigit(numbersList[i])) {
            counter++;
            sum += (int)(numbersList[i] - '0');
          }
        }
      }
      Console.WriteLine("{0} {1}", counter, sum);
    }
  }
}