Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

Elena123456 avatar Elena123456 235 Точки

*4. Phone: Arrays - More Exercises

Днес, докато търсех допълнителните упражнения за масиви попаднах на една задача от 2017г , която е отпаднала в сегашните курсове на C# Fundamentals: https://judge.softuni.bg/Contests/Practice/Index/422#3  Стори ми се доста интересна и реших да я направя, но получих 0/100 за жалост. Мисля, че проблема ми е отново при принтирането на минутите и секундите след изчисляването на сумата от числата на получения телефонен номер, тоест от получената сума на числата трябва да получим минути и секунди. Мисля, че този път не е проблема в MonoDevelop. Моля, ако някой може да погледне последните три реда от кода ми, защото само те не излизат правилно в аутпута и като цяло метода sum(). https://pastebin.com/ynfGYjzD

 

While I was searching today for additional exercises about arrays  I stumble upon one exercise from 2017, which is not included today in C# Fundamental module: https://judge.softuni.bg/Contests/Practice/Index/422#3 I have decided to give it a try, but unfortunately I scored 0/100. I think the problem is in my print method for minutes and seconds after calculate the sum of digits in given phone number. Exactly from current sum of digits  we have to print minutes and second for call duration. I think this time the root of problem is not a MonoDevelop. Can somebody please help me out and give me feedback why my code is not working, I will be very grateful. I think the problem is in the last three lines in my code and in sum().

https://pastebin.com/ynfGYjzD

 

3. Phonebook-previous problem

You will be given an array of phone numbers (strings) and an array of names (strings). After which, you will be given strings on new lines, until you receive the command “done”. Find the numbers, which correspond to the names and print them on the console in the following format:

  • {name} -> {number} // (this line is not included in my task)

A number corresponds to a name when it’s located on the same position as its corresponding name in both arrays.

 

4.* Phone- my problem

This is an upgrade of the previous problem. Implement the phonebook functionality from the previous problem with this additional functionality:

  • call {number/name} -> print “calling {name/number}…

    • If the sum of the digits (ignore other characters) of the number is odd, print “no answer”.

    • If the sum of the digits (ignore other characters) of the number is even, print “call ended. duration: {duration}”. The duration is calculated from the sum of the digits in the format “mm:ss

  • message {number/name} -> print “sending sms to {name/number}...

    • if the difference of the digits (ignore other characters) of the number is odd, print “busy

    • if the difference of the digits (ignore other characters) of the number is even, print “meet me there

 

Input

0888888888 0888123456 +359886001122

Nakov Ivan Maria

call 0888888888

call Ivan

message Maria

done

 

 

Output:

 

calling Nakov...

call ended. duration: 01:12

calling 0888123456...

no answer

sending sms to +359886001122...

busy

 

Output in Judge: 0/100

calling Nakov...
call ended. duration: 09:12
calling 0888123456...
no answer
sending sms to +359886001122...
busy

 

Тагове:
0
C# Fundamentals 03/10/2020 01:33:54
Axiomatik avatar Axiomatik 2422 Точки
Best Answer

Everything is OK, just for the call-duration you were adding the ASCII-value instead of the actual int value.

Best,

        private static void CalculateSumOfDigitsAndPrintAnswer(string phoneNumber)
        {
            int sum = 0;
            for (int i = 0; i < phoneNumber.Length; i++)
            {
                if (int.TryParse(phoneNumber[i].ToString(), out int result))
                {
                    sum += result;
                }

                // Alternative
                //int currentNum = int.Parse(phoneNumber[i].ToString())
                //sum += currentNum;
            }

            if (sum % 2 != 0)
            {
                Console.WriteLine("no answer");
            }
            else if (sum % 2 == 0)
            {
                int minutes = sum / 60;
                int secundes = sum % 60;
                Console.WriteLine($"call ended. duration: {minutes:D2}:{secundes:D2}");
            }
        }

1
Elena123456 avatar Elena123456 235 Точки

Thanks again!

I was adding also ASCII value and for differences, but I corrected it. I chose the first way, because directly taken int result.

  •   for (int i = 0; i < phoneNumber.Length; i++)

            {

                if (int.TryParse(phoneNumber[i].ToString(), out int result))

                {

                    difference = difference - result;

                }

            }

 

I have already working code thanks to you: https://pastebin.com/NBLpAY9T And this was my last exercise before exam preparation. I have solved twice all exercises in Fundamental module without one about Longest Increasing Subsequence with Dinamic programming. I don't worry about that, because I will take algorithm course with Dinamic programing after my C# OOP. And really I think to programming with MonoDevelop is potential risk for C#Advanced and OOP.

Best regards!

Eli

1
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.