Loading...

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

Lusien.GG avatar Lusien.GG 66 Точки

encodedAnswers - Basics Practice

Здравейте в judge ми дава 60/100 с 4 runtime errors. Въпросът ми е защо...?

 

Prof. Petrov is teaching Public Finance in the Faculty of Economics and Business Administration. At the end of the term he grades his students based on a test which he strictly prepares. However, last year some of the students sneaked into his room and stole the answer key to the test. This year he had decided to be more careful about keeping the answer key secret, so he asks you to help him encode the answers, so that even if students find it again, they will not be able to read it.
Your task is to write a program, which gets as input the number of the questions in the test and then on a separate line for each question is given a number. Since each question has 4 possible answers, there are 4 types of numbers which will be given. If the given number is divisible by 4 (that means the reminder of the division equals 0), the answer to that question is ‘a’. If the reminder of the division of the number by 4 equals 1, the answer is ‘b’; if it equals 2, the answer is ‘c’; and if it equals 3, the answer is ‘d’. At the end, the program should print on the console all the answers in letter format in a single line. After that, in the next 4 lines, it should print the number of answers of each type – a, b, c, and d.
Input
On the first line you will receive the number N – the number of questions in the test.
On the next N lines you will receive valid integer numbers in range 0 to 4,294,967,295
Output
On the first line, display all the answers in format a, b, c or d.
On the next 4 lines – on each line print the type of answer (a, b, c or d) and how many answers of this type are there in the test.
Example: “Answer A: 15”
Constraints
N is an integer in range [1 … 30]
The numbers for answers will be in range [0…4,294,967,295]
Allowed memory: 16 MB
Allowed time: 0.1s

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace encodedAnswers
{
    class answers
    {
        static void Main(string[] args)
        {
            var questions = int.Parse(Console.ReadLine());
            int[] answers = new int[29];
            char[] uncodedAnswers = new char[29];
            int a = 0;
            int b = 0;
            int c = 0;
            int d = 0;
            for (int i = 0; i < questions; i++)
            {
                answers[i] = int.Parse(Console.ReadLine());
                answers[i] = answers[i] % 4;
                switch (answers[i])
                {
                    case 0:
                        uncodedAnswers[i] = 'a';
                        a++;
                        break;
                    case 1:
                        uncodedAnswers[i] = 'b';
                        b++;
                        break;
                    case 2:
                        uncodedAnswers[i] = 'c';
                        c++;
                        break;
                    case 3:
                        uncodedAnswers[i] = 'd';
                        d++;
                        break;
                }
            }

            for (int i = 0; i < questions; i++)
            {
                Console.Write(uncodedAnswers[i]+" ");
            }
            Console.WriteLine();
            Console.WriteLine("Answer A: {0}",a);
            Console.WriteLine("Answer B: {0}", b);
            Console.WriteLine("Answer C: {0}", c);
            Console.WriteLine("Answer D: {0}", d);

        }
    }
}

 


Благодаря :)

0
Programming Basics 16/03/2016 20:09:32
djc_bg2015 avatar djc_bg2015 923 Точки
Best Answer

Така, помисли в/у следните 2 неща:

  • N is an integer in range [1 … 30]
  • The numbers for answers will be in range [0…4,294,967,295]

Колко голям масив ти трябва за да събереш числата от 1 - 30 ако ще ги ползваш като индекси при достъпването на  въпросния масив?

Колко е лимита на System.Int32 (int)?

 

Поздрави!

 

ПС. С 2 минимални редакции, кода ти дава 100 точки в джъдж.

3
16/03/2016 18:39:18
Lusien.GG avatar Lusien.GG 66 Точки

Благодаря, открих си нещата :)

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