1 / 4
Apr 2011

Help.. WA S:

using System;
class Decoding
{
    static void Main()
    {
        long T; //casos
        string n; //numeros hallar suma factores
        int k;
        T = Convert.ToInt64(Console.ReadLine());
    

    for (k = 0; k < T; k++)
    {
        n = Console.ReadLine();
        
        Console.WriteLine(decode(n));
    }
   
}

static string decode(string a)
{
    string r = ""; //repetir
    string d = ""; //devolucion
    bool s = true; //para sacar de ciclos
    int k = 0;

    while (s)
    {
        if (a[k] == '2' || a[k] == '3' || a[k] == '4' ||
            a[k] == '5' || a[k] == '6' || a[k] == '7' ||
            a[k] == '8' || a[k] == '9')              
        {
            r = "";
            int c = Convert.ToInt32(Convert.ToString(a[k]));
            while (c-- > 0)
            {
                r += Convert.ToString(a[k + 1]);
                
            }
            d += r;
            k += 2;
            if (k > a.Length - 1) return d;
        }

        
        
        if (a[k] == '1' && a[k + 1] != '1')
        {
            ++k;
            r = "";
            while (a[k] != '1')  r += a[k++];
            d += r;
            ++k;
            if (k > a.Length - 1) return d;
        }

        
        if (a[k] == '1' && a[k + 1] == '1')
        { r = "";  d += 1; k += 2;
        if (d == "11") return d; 
        if (k > a.Length - 1) return d;
        }

        if (k > a.Length - 1) s = false;
        else s = true;
    }

    return d;
}
}

*Sorry for the code size, I have to improve my programmer skills really much more...

  • created

    Apr '11
  • last reply

    Apr '11
  • 3

    replies

  • 422

    views

  • 2

    users

My output is 9876543..
Because of the between 1s proposition;
I think I'm getting lost in this: " If a 1 appears as part of the sequence, it is escaped with a 1, thus two 1 characters are output."
I can't understand it, due to my bad english...

Is it that: if you see a 1, and another 1 next, you must return only one 1 ?

You have taken that statement out of context.

91876543