Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string input = Console.ReadLine();
- bool isDiam = false;
- int startIndex = input.IndexOf("<");
- while (startIndex != - 1)
- {
- int endIndex;
- string diamond = string.Empty;
- endIndex = input.IndexOf(">", startIndex + 1);
- if (endIndex - startIndex > 0)
- {
- diamond = input.Substring(startIndex + 1, endIndex - startIndex - 1);
- }
- startIndex = input.IndexOf("<", startIndex + 1);
- int sum = 0;
- for (int i = 0; i < diamond.Length; i++)
- {
- if (Char.IsDigit(diamond[i]))
- {
- sum += diamond[i] - '0';
- }
- }
- if (sum > 0)
- {
- Console.WriteLine($"Found {sum} carat diamond");
- isDiam = true;
- }
- }
- if (!isDiam)
- {
- Console.WriteLine("Better luck next time");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement