Advertisement
gabiivanova

PetarsGame

Feb 3rd, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3. using System.Text;
  4.  
  5. class PetersGame
  6. {
  7.     static void Main()
  8.     {
  9.         ulong starting = ulong.Parse(Console.ReadLine()); //10
  10.         ulong end = ulong.Parse(Console.ReadLine()); //14
  11.         string replacement = Console.ReadLine(); //a  
  12.  
  13.         BigInteger sum = 0;
  14.         string replays = string.Empty;
  15.         string result = string.Empty;
  16.  
  17.         for (ulong i = starting; i < end; i++)
  18.         {
  19.             if (i % 5 == 0)
  20.             {
  21.                 sum += i;
  22.             }
  23.             else
  24.             {
  25.                 sum += i % 5;
  26.             }
  27.         }
  28.  
  29.         replays = sum.ToString();
  30.         if (sum % 2 == 0)
  31.         {
  32.             char toReplace = replays[0];
  33.             result = ReplaceInString(toReplace, replays, replacement);
  34.         }
  35.         else
  36.         {
  37.             char toReplace = replays[replays.Length - 1];
  38.             result = ReplaceInString(toReplace, replays, replacement);
  39.         }
  40.         Console.WriteLine(result);
  41.     }
  42.  
  43.     public static string ReplaceInString(char toReplace, string replays, string inputReplace)
  44.     {
  45.         string result = "";
  46.         for (int i = 0; i < replays.Length; i++)
  47.         {
  48.             if (replays[i] == toReplace)
  49.             {
  50.                 result += inputReplace;
  51.             }
  52.             else
  53.             {
  54.                 result += replays[i];
  55.             }
  56.         }
  57.  
  58.         return result;
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement