Задача "Old Books" 90/100т.
Здравейте колеги, опитах какво ли не, но ми дава 90 от 100 точки. Ще съм благодарна , ако някой ми покаже къде греша.
https://pastebin.com/AVHAG23e
Здравейте колеги, опитах какво ли не, но ми дава 90 от 100 точки. Ще съм благодарна , ако някой ми покаже къде греша.
https://pastebin.com/AVHAG23e
using System;
 
namespace Account_Balance
{
    class Program
    {
        static void Main(string[] args)
        {
 
            string nameOfTheBook = Console.ReadLine();
            string booksInLabrary = Console.ReadLine();
            // double counter = 1;
            double counter = 0;
 
            while (true)
            {
                if (booksInLabrary == "No More Books")
                {
                    Console.WriteLine("The book you search is not here!");
                    Console.WriteLine($"You checked {counter} books.");
                    break;
                }
                else if (booksInLabrary == nameOfTheBook)
                {
                    Console.WriteLine($"You checked {counter} books and found it.");
                    break;
                }
                counter++;
 
                booksInLabrary = Console.ReadLine();
            }
        }
    }
}
 
Здравей sotirova.yulia,
Допускаш две основни грешки:
1)Не прочиташ правилно входните данни
2)Не следваш правилната логика на задачата
Ето едно кратко решение:
using System;
namespace Old_Books
{
    class Program
    {
        static void Main(string[] args)
        {
            string city = Console.ReadLine();
            int capacity = int.Parse(Console.ReadLine());
            int counter = 0;
            while(true)
            {
                string currentCity = Console.ReadLine();                
                if(currentCity==city)
                {
                    Console.WriteLine($"You checked {counter} books and found it.");
                    return;
                }
                else
                {
                    if(counter==capacity)
                    {
                        Console.WriteLine($"The book you search is not here!");
                        Console.WriteLine($"You checked {counter} books.");
                        return;
                    }
                }
                counter++;
            }
        }
    }
}
 
Много благодаря!