Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _3.Imunne_System
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int initialHealth = int.Parse(Console.ReadLine());
  14.             var dictionary = new Dictionary<string, int>();
  15.  
  16.             var levelOfHealth = initialHealth;
  17.             var finalHealth = 0;
  18.  
  19.             while (true)
  20.             {
  21.                 char[] input = Console.ReadLine().ToArray();
  22.  
  23.                 string check = new string(input);
  24.                 if (check == "end")
  25.                 {
  26.                     break;
  27.                 }
  28.  
  29.                 var sumForInput = 0;
  30.  
  31.                 for (int i = 0; i < input.Length; i++)
  32.                 {
  33.                     int resultForNumber = (int)input[i];
  34.                     sumForInput += resultForNumber;
  35.                 }
  36.  
  37.                 var virusStrength = sumForInput / 3;
  38.                 var virusTimeToDefeat = virusStrength * input.Length;
  39.                 var minutesDefeat = virusTimeToDefeat / 60;
  40.                 var secondsDefeat = virusTimeToDefeat % 60;
  41.                
  42.                 if (dictionary.ContainsKey(check))
  43.                 {
  44.                     var numberOfTimesVirusDetected = 0;
  45.                     var something = dictionary.TryGetValue(check, out numberOfTimesVirusDetected);
  46.                     dictionary[check] = numberOfTimesVirusDetected + 1;
  47.                     if (dictionary[check] == 2)
  48.                     {
  49.                         virusTimeToDefeat = virusTimeToDefeat / 3;
  50.                         minutesDefeat = virusTimeToDefeat / 60;
  51.                         secondsDefeat = virusTimeToDefeat % 60;
  52.                     }
  53.                 }
  54.                 dictionary[check] = 1;
  55.                
  56.                
  57.  
  58.                 var currentHealth = levelOfHealth - virusTimeToDefeat;
  59.  
  60.                 Console.WriteLine($"Virus {check}: {virusStrength} => {virusTimeToDefeat} seconds");
  61.                 if (currentHealth > 0)
  62.                 {
  63.                     Console.WriteLine($"{check} defeated in {minutesDefeat}m {secondsDefeat}s.");
  64.                     Console.WriteLine($"Remaining health: {currentHealth}");
  65.  
  66.                     levelOfHealth = currentHealth + (int)(currentHealth * 0.20);
  67.  
  68.                     if (levelOfHealth > initialHealth)
  69.                     {
  70.                         levelOfHealth = initialHealth;
  71.                     }
  72.                     finalHealth = currentHealth;
  73.                 }
  74.                 else
  75.                 {
  76.                     finalHealth = currentHealth;
  77.                     Console.WriteLine("Immune System Defeated.");
  78.                     break;
  79.                 }
  80.             }
  81.             if (finalHealth > 0)
  82.             {
  83.                 Console.WriteLine($"Final Health: {levelOfHealth}");
  84.             }
  85.  
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement