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);
}
}
}
Благодаря :)
Благодаря, открих си нещата :)