Помогите, пожалуйста, решить. Выбрать из массива А в массив В все числа, которые встречаются не более 2 раз в языке C#
Ответы
using System;
namespace App {
class Program {
static void Main(string[] args) {
int n = Convert.ToInt32(Console.ReadLine());
int[] a = new int[n];
int[] b = new int[0];
Random rand = new Random();
for (int i = 0; i < n; i++) {
a[i] = rand.Next(0, 11);
Console.Write(a[i] + " ");
}
int num= Int32.MaxValue;
Array.Sort(a); Console.WriteLine();
for (int i = 0; i < n; i++) {
if (a[i] != num) {
int c = 0;
for (int j = i; j < n; j++) if (a[i] == a[j]) { c++; num = a[i]; }
if (c <= 2) {
Array.Resize(ref b, b.Length + 1);
b[b.Length - 1] = a[i];
}
}
}
for (int i = 0; i < b.Length; i++) Console.Write(b[i] + " ");
Console.ReadKey();
}
}
}
a2.https://znanija.com/task/29332995
a3.https://znanija.com/task/29332997
a4.https://znanija.com/task/29333001
a5.https://znanija.com/task/29333004
a6.https://znanija.com/task/29333008
a7.https://znanija.com/task/29333010
a8.https://znanija.com/task/29333012
a9.https://znanija.com/task/29333016
a10.https://znanija.com/task/29333017
a12.https://znanija.com/task/29333023
a13.https://znanija.com/task/29333026
a14.https://znanija.com/task/29333028
a15. https://znanija.com/task/29333030
a16.https://znanija.com/task/29333032
b1.https://znanija.com/task/29333036
b2.https://znanija.com/task/29333048
b3.https://znanija.com/task/29333048
b4.https://znanija.com/task/29333051
b5.https://znanija.com/task/29333054
b6.https://znanija.com/task/29333058
b8.https://znanija.com/task/29333059
b9.https://znanija.com/task/29333062
b11.https://znanija.com/task/29333066
b12.https://znanija.com/task/29333068
b14.https://znanija.com/task/29333071
b15.https://znanija.com/task/29333073
b16.https://znanija.com/task/29333078
b17.https://znanija.com/task/29333088
b18.https://znanija.com/task/29333082
b19.https://znanija.com/task/29333083
20 баллов за каждое .Заранее благодарен!