1 / 3
Apr 2011

Hi,
I thought I solved "Making Book" (1872, MKBOOK) problem, because it runned before I uploaded to the judge,
but when I did, it got runtime error (NZEC),
I want to know why to be able to fix it...

Help, please S:

using System;
class MakingBooks
{
    static void Main()
    {
        int k = 0;
        long a = 1, b;
        bool s = true;
        while (s)
        {
            string[] n = new string[2]; // separated
            string m = Console.ReadLine();
            n = m.Split(' ');
            a = Convert.ToInt64(n[0]);
            if (m != "0")
            {
                    b = Convert.ToInt64(n[1]);
                    Console.WriteLine("Case " + Convert.ToString(k += 1) + ": " + makingBooks(a, b));
            }
            else  s = false;
        }
    }
    static string makingBooks(long a, long b)
{
    string[] n = new string[b - a + 1]; // arreglo con los numeros del intervalo
    int l = 0; //lugares
    long[,] r = new long[2, 10]; //numeros
    string s = ""; //solución

    for (int q = 0; q <= 9; q++) r[0, q] = q;

    for (long k = a; k <= b; k++) n[l++] = Convert.ToString(k);
            
    for (int q = 0; q <= 9; q++)
            for (long c = 0; c < l ; c++) 
                if(cuentadig(q, n[c]) != 0) r[1, q] += cuentadig(q, n[c]);

    for (int q = 0; q <= 9; q++)
        s += Convert.ToString(q) + ":" + Convert.ToString(r[1, q]) + " ";

    return s;
}

static int cuentadig(int a, string b)
    {
   // 2 – obtiene la cantidad de bs en a
   int c = 0; // cantidad de espacios
   for (int k = 0; k < b.Length; k++)
      if (Convert.ToString(b[k]) == Convert.ToString(a)) c++;
   return c;
}
}
  • created

    Apr '11
  • last reply

    Apr '11
  • 2

    replies

  • 261

    views

  • 2

    users