Поиск индекса числа в массиве () - C#
Формулировка задачи:
Здравствуйте есть задача, я её решил, но не проходит тест (тест онлайн). Подскажите пожалуйста что я не верно сделал? Спасибо!
Задание:
Suppose we are given two sequences of numbers. All numbers in the first sequence are sorted. For each element from the second sequence print the index where an element must be inserted into the first sequence without breaking the sorting. In case when element b of the second sequence is in the first sequence, the lowest index for element b, which does not break the sorting must be printed. The indexes start from 0. The input data are integer numbers. All numbers are separated by spaces. First number n is a number of members of the first sequence. Next n numbers are elements of the first sequence. Next number m is a number of members of the second sequence. Next m numbers are elements of the second sequence. Input data guarantees that the inputs and the result will be less than 2 147 483 647. Output data must be a number of elements of the second sequence and indexes for each element of the second sequence, where they must be inserted into the first sequence without breaking the sorting. All numbers must be separated by spaces.
код:
P.S. Console.ReadKey не нужен.
var input = Console.ReadLine(); var numbers = input.Split(' ').Select(x => int.Parse(x)).ToArray(); var mass_A = new int[numbers[0]]; var mass_B = new int[numbers[numbers[0] + 1]]; var position_B = numbers[numbers[0] + 1]; Array.Copy(numbers, 1, mass_A, 0, numbers[0]); Array.Copy(numbers, numbers[0] + 2, mass_B, 0, position_B); List<int> list = new List<int>(); Console.Write(mass_B.Length); for (int i=0; i < mass_B.Length; i++) { list.Clear(); list = mass_A.OfType<int>().ToList(); list.Add(mass_B[i]); list.Sort(); Console.Write(" " + list.IndexOf(mass_B[i])); }
Решение задачи: «Поиск индекса числа в массиве ()»
textual
Листинг программы
var mass_A = new int[numbers[0]]; var mass_B = new int[numbers[numbers[0] + 1]]; var position_B = numbers[numbers[0] + 1]; Array.Copy(numbers, 1, mass_A, 0, numbers[0]); Array.Copy(numbers, numbers[0] + 2, mass_B, 0, position_B);
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д