Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. public class PetarsGame
  5. {
  6.     public static void Main()
  7.     {
  8.         ulong startNumber = ulong.Parse(Console.ReadLine());
  9.         ulong endNumber = ulong.Parse(Console.ReadLine());
  10.         string replacement = Console.ReadLine();
  11.  
  12.         BigInteger sum = 0;
  13.  
  14.         for (ulong currentNumber = startNumber; currentNumber < endNumber; currentNumber++)
  15.         {
  16.             if (currentNumber % 5 == 0)
  17.             {
  18.                 sum += currentNumber;
  19.             }
  20.             else
  21.             {
  22.                 sum += currentNumber % 5;
  23.             }
  24.         }
  25.  
  26.         string sumAsString = sum.ToString();
  27.         string digitToReplace;
  28.  
  29.         if (sum % 2 == 0)
  30.         {
  31.             digitToReplace = sumAsString[0].ToString();
  32.         }
  33.         else
  34.         {
  35.             digitToReplace = sumAsString[sumAsString.Length - 1].ToString();
  36.         }
  37.  
  38.         sumAsString = sumAsString.Replace(digitToReplace, replacement);
  39.  
  40.         Console.WriteLine(sumAsString);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement