BorislavBorisov

33.08.Astrological Digits мое решение добро

Feb 6th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2. class AstrologicalDigits
  3. {
  4.     static void Main()
  5.     {
  6.         string N = Console.ReadLine();
  7.         int index = 0;
  8.         int sum = 0;
  9.  
  10.         while (true)
  11.         {
  12.             if (N[index] == '.' || N[index] == '-')
  13.             {
  14.                 index = index + 1;
  15.                 continue;
  16.             }
  17.             else
  18.             {
  19.                 sum += Convert.ToInt32(N[index] - '0');
  20.                 if (index == N.Length - 1 && sum > 10)
  21.                 {
  22.                     index = -1;//трябва да е така, а не нула
  23.                     N = Convert.ToString(sum);
  24.                     sum = 0;
  25.                 }
  26.                 else if (index == N.Length - 1 && sum < 10)
  27.                 {
  28.                     break;
  29.                 }
  30.                 index = index + 1;
  31.             }
  32.         }
  33.         Console.WriteLine(sum);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment