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

Автор SayaPintar, история, 3 года назад, По-английски

my code written with c# give wrong output, im fail in testcase 7

Testcase: 5 5 3 2 1 0 0 this my code:

static void Main(string[] args) { string input = Console.ReadLine(); string[] proses = input.Split(' ');

//inputan setiap array.
        string Inputn = Console.ReadLine();
        string[] array = Inputn.Split(' ');
        int[] array1 = new int[int.Parse(proses[0])];
        //
        //base case
        for(int x =0; x < array.Length; x++)
        {
            array1[x] = int.Parse(array[x]);
        }
       int pos = int.Parse(proses[1]);
       int basis = int.Parse(array[pos-1]);
        //
        int count = 0;
       if (basis == 0 && array1.Sum() == 0)
        {
            Console.WriteLine(0);
        }
        else
        {
           for(int c =0; c < array1.Length; c++)
            {
                if(array1[c] >= array1[basis - 1] && array1[c] > 0)
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
        Console.ReadLine();

    }

i think my code was give correct result(i think 5) but expected 3...

anyone help me.. i wonder how why my code doesnt work?

another note: i rebuild my code and im not use Linq (Where) and work perfectly if i do that with manually.

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