vazhadval's blog

By vazhadval, history, 4 weeks ago, In English,

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);
    }
}

}

 
 
 
 
  • Vote: I like it  
  • +2
  • Vote: I do not like it  

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

I understand , thank you :)