Advertisement
dimipan80

Telerik Exam. Nightmare on Code Street

Jun 24th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. namespace _2.NightmareOnCodeStreet
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class NightmareOnCodeStreet
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             checked
  12.             {
  13.                 string inputText = Console.ReadLine();
  14.  
  15.                 string[] symbols = new string[inputText.Length];
  16.                 for (int i = 0; i < symbols.Length; i++)
  17.                 {
  18.                     symbols[i] = inputText[i].ToString();
  19.                 }
  20.  
  21.                 int countOdds = 0;
  22.                 long sumOdds = 0;
  23.                 for (int i = 0; i < symbols.Length; i++)
  24.                 {
  25.                     bool isDigit = false;
  26.                     byte digit;
  27.                     if (byte.TryParse(symbols[i], out digit))
  28.                     {
  29.                         isDigit = true;
  30.                     }
  31.  
  32.                     if (isDigit && (i % 2) != 0)
  33.                     {                        
  34.                         sumOdds += digit;
  35.                         countOdds++;                        
  36.                     }
  37.                 }              
  38.  
  39.                 Console.WriteLine("{0} {1}", countOdds, sumOdds);
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement