Блог пользователя vazhadval

Автор vazhadval, история, 6 лет назад, По-английски

I get "runtime error on test 1" message and I think my code is OK

Problem name: Theater Square

CODE:

using System;

namespace ConsoleApp6 { class Program { static void Main(string[] args) {

int n = Convert.ToInt32(Console.ReadLine());
        int m = Convert.ToInt32(Console.ReadLine());
        int a = Convert.ToInt32(Console.ReadLine());
        int m1 = 0;
        int n1 = 0;
        if (a >= m)
        {
            m1 = 1;
        }
        if(a<m)
        {
            m1 = m / a + 1;
        }
        if (a >= n)
        {
            n1 = 1;
        }
        if(a<n)
        {
            n1 = n / a + 1;
        }
        Console.WriteLine(m1 * n1);
    }
}

}

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

The problem is in the way of getting the input.

Search for how you can get many data given in one line in C#.

Tell me if you don't get the information needed.

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

When the line "Console.ReadLine()" runs, it reads the whole string which contains all numbers given in the input. So, when the line "int m = Convert.ToInt32(Console.ReadLine());" runs, there is no more numbers on the input.

In other words: in that task you call "ReadLine()" 3 times. But the input have only one string. So, When you call "ReadLine()", you read all the input. You should call "ReadLine()" only once here

»
6 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

I understand , thank you :)