Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Nether Realms w/o using regex, just parsing the string
- // Programming Fundamentals Exam - Part 2 - 23 October 2016
- // https://judge.softuni.bg/Contests/Practice/Index/349#0
- // 100 / 100
- // Memory: 9.30 MB
- // Time: 0.015 s
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace NetherRealms
- {
- class Program
- {
- static void Main()
- {
- string[] separators = { " ", "," };
- List<string> demons = Console.ReadLine()
- .Split(separators, StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- demons.Sort();
- foreach (string demon in demons)
- ParseDemonInfo(demon);
- }
- private static void ParseDemonInfo(string s)
- {
- int health = 0,
- multCount = 0,
- divCount = 0;
- StringBuilder sb = new StringBuilder();
- foreach (char ch in s)
- switch (ch)
- {
- case '*':
- multCount++;
- sb.Append(' ');
- break;
- case '/':
- divCount++;
- sb.Append(' ');
- break;
- case '+':
- case '-':
- sb.Append(' ');
- sb.Append(ch);
- break;
- default:
- if (char.IsDigit(ch) || ch.Equals('.'))
- sb.Append(ch);
- else
- {
- health += ch;
- sb.Append(' ');
- }
- break;
- }
- double damage = sb.ToString()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(double.Parse)
- .ToArray()
- .Sum();
- damage *= Math.Pow(2, multCount - divCount);
- Console.WriteLine($"{s} - {health} health, {damage:F2} damage");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment