Поиск символа в строке - C# (178010)
Формулировка задачи:
Есть два массива которые вводится с клавиатуры, нужно вывести массив в котором символов "7" больше. Проблема в том что нужно что бы засчитывало"семерки" не только в "7", но и "17", "27" или "1007" .
class Massive
{
private int[] a;
private int[] b;
public Massive()
{
Console.Write("Введите р-р массива A \n");
int n1=int.Parse(Console.ReadLine());
a=new int[n1];
Console.Write("Введите элементы массива A \n");
for(int i1=0;i1<a.Length;i1++) a[i1]=int.Parse(Console.ReadLine());
Console.Write("Введите р-р массива B \n");
int n2=int.Parse(Console.ReadLine());
b=new int[n2];
Console.Write("Введите элементы массива B \n");
for(int i2=0;i2<b.Length;i2++) b[i2]=int.Parse(Console.ReadLine());
}
public int[] A
{
get {return a;}
set {a = value;}
}
public int [] B
{
get {return b;}
set {a=value;}
}
}
public class Program
{
public static void Main()
{
Massive massive = new Massive();
Console.WriteLine("Вывод всего массива A");
for (int i = 0; i < massive.A.Length; i++)
Console.Write(massive.A[i] + "\t");
string [] strA= massive.A.Select(x=>x.ToString()).ToArray(); //в массив строк
Console.WriteLine("\n Строка:");
string.Concat(strA);
Console.WriteLine(string.Concat(strA));//в строку
int z=strA.Count(c => c == "7");// проблема тут, т.к. таким образом не засчитывается 27,17 и тд
Console.WriteLine(z);Решение задачи: «Поиск символа в строке»
textual
Листинг программы
static int Count7(int[] arr)
{
int count = 0;
foreach (int item in arr)
{
int n = item;
while (n > 0)
{
if (n % 10 == 7)
count++;
n /= 10;
}
}
return count;
}