Задача 1.Extract Person Information - Text Processing More Exercises - 0/100
Колеги, моля за съдействие. Нулевите тестове минават. Резултатът е, обаче, 0/100. Ето и кода:
Колеги, моля за съдействие. Нулевите тестове минават. Резултатът е, обаче, 0/100. Ето и кода:
Здравей! 
Ето едно решение: 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Extract_Person_Information
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                string input = Console.ReadLine();
                int indexOfNameStart = input.IndexOf('@');
                int indexOfNameEnd = input.IndexOf('|');
                string name = input.Substring(indexOfNameStart+1, indexOfNameEnd - indexOfNameStart-1);
                int indexOfAgeStart = input.IndexOf('#');
                int indexOfAgeEnd = input.IndexOf('*');
                string ageStr = input.Substring(indexOfAgeStart + 1, indexOfAgeEnd - indexOfAgeStart-1);
                Console.WriteLine($"{name} is {ageStr} years old.");
            }
        }
    }
}
Много удобно се решава тази задача с регекс:
using System;
using System.Text.RegularExpressions;
namespace ExtractPersonInformation_MoreEx
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                string text = Console.ReadLine();
                string namePattern = @"@(?<name>[A-Za-z]+)\|";
                string agePattern = @"#(?<age>[0-9]+)\*";
                Match name = Regex.Match(text, namePattern);
                Match age = Regex.Match(text, agePattern);
                Console.WriteLine($"{name.Groups["name"]} is {age.Groups["age"]} years old.");
            }
        }
    }
}
 
Здравейте, къде бъркам в решението на JAVA с Regex? Разгледах решението с substring, и то ми е ясно. Но къде бъркам тук?
ExtractPersonInformation - Pastebin.com
Пове4е ме интересува грешката в логиката, отколкото 100/100.
Намерих си грешката:
String age = matcherAge.group("age");  (не - String age = matcherName.group)
using System;
using System.Linq;
class SoftUni {
    static void Main() {
        for (int n = int.Parse(Console.ReadLine()); n > 0; n--) {
            string input = Console.ReadLine();
            string name = input.Split('@')[1].Split('|')[0];
            string age = input.Split('#')[1].Split('*')[0];
            Console.WriteLine($"{name} is {age} years old.");
        }
    }
}
Може да ги split по специалните знаци, да вземем втория елемент, да split отново и да вземем първия елемент. 100/100
Предлагам и моето решение за Python със slice notation и намиране на индекса на конкретният знак.
n = int(input())
for i in range(n):
    curr_text = input()
    name_start_index = curr_text.index("@")
    name_stop_index = curr_text.index("|")
    age_start_index = curr_text.index("#")
    age_stop_index = curr_text.index("*")
    name = curr_text[name_start_index + 1:name_stop_index]
    age = curr_text[age_start_index + 1:age_stop_index]
    print(f"{name} is {age} years old.")
или накратко:
n = int(input())
for i in range(n):
    curr_text = input()
    print(f"{curr_text[curr_text.index('@') + 1:curr_text.index('|')]} is {curr_text[curr_text.index('#') + 1:curr_text.index('*')]} years old.")
        
Благодаря. Логиката ми гърми при вход abc@George|. С IndexOf е лесно, кратко и бързо :)