Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class DiamondProblem
- {
- static void Main()
- {
- var input = Console.ReadLine();
- var sum = 0;
- var caratsOfDiamonds = new List<int>();
- var isDiamond = false;
- foreach (var symbol in input)
- {
- if (symbol == '<')
- {
- isDiamond = true;
- }
- else if (symbol == '>')
- {
- caratsOfDiamonds.Add(sum);
- sum = 0;
- isDiamond = false;
- }
- if (isDiamond == true)
- {
- if (char.IsDigit(symbol))
- {
- sum += symbol - '0';
- }
- }
- }
- var isAnyDiamond = caratsOfDiamonds.Sum(x => x);
- if (isAnyDiamond == 0)
- {
- Console.WriteLine($"Better luck next time");
- }
- else
- {
- foreach (var carats in caratsOfDiamonds)
- {
- Console.WriteLine($"Found {carats} carat diamond");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement