This code works only for certain values of size like (1<And it will work fine when i read all input into a byte array in a continuous fashion. But read > process data , read gives wrong answer
Why is there anything wrong with the read method() in Mono
Since i have checked for all values of size, 1 to 50
it gives right answer in my Microsoft C# compiler
Any reason ??
using System;
using System.IO;
class Program
{
static int size = 1 << 16, i;
static byte[] b;
static int ReadInt()
{
while (true)
{
try
{
while (b[i] < '0') i++;
break;
}
catch
{
Console.OpenStandardInput().Read(b, 0, size);
i = 0;
}
}
int m = 0, r;
while (true)
{
try
{
while ((r = b[i] - '0') >= 0)
{
m = m * 10 + r;
i++;
}
break;
}
catch
{
Console.OpenStandardInput().Read(b, 0, size);
i = 0;
}
}
return m;
}
static void Main(string[] args)
{
int n, d, m, count = 0;
i = 0;
b = new byte[size];
Console.OpenStandardInput().Read(b, 0, size);
n = ReadInt();
d = ReadInt();
while (n-- > 0)
{
m = ReadInt();
if (m % d == 0) count++;
}
Console.WriteLine(count);
}
}