using System;
using System.Collections.Generic;
using System.Linq;
namespace
{
class App
static void Main(string[] argv)
App Obj = new App();
Obj.Run();
}
public bool IsContains(string Word, char searched_lit)
char[] lits = Word.ToCharArray();
foreach (char lit in lits)
if (lit == searched_lit)
return true;
return false;
public void Run()
int N = Convert.ToInt32(Console.ReadLine());
List<string> nums = new List<string>();
List<int> dual_number = new List<int>();
for (int i = 1; i <= N; i++)
nums.Add(Console.ReadLine());
foreach (string word in nums)
if (word.Length == 2)
if (IsContains(word, '4'))
dual_number.Add(Convert.ToInt32(word));
int result=0;
dual_number.ForEach(x => result += x);
Console.WriteLine(result / dual_number.Count);
Console.ReadKey();
Объяснение:
#include <iostream>
using namespace std;
int main()
setlocale(LC_ALL, "Rus");
int n, j;
cout << "введите длину массива ";cin >> n;
int* A = new int[n];
cout << "Введите массив " << endl;
for (int i = 0; i < n; i++) //ввод массива
cin >> A[i];
for (int i = n - 1; i >= 0; i--)
j = i;
while (A[j] == 0 && A[1 + j] != 0 && j + 1 < n)
int tmp = A[j + 1];
A[j + 1] = A[j];
A[j] = tmp;
j++;
cout << "новый массив ";
for (int i = 0; i < n; i++)
cout << A[i]<<" ";
delete[] A;
return 0;
using System;
using System.Collections.Generic;
using System.Linq;
namespace
{
class App
{
static void Main(string[] argv)
{
App Obj = new App();
Obj.Run();
}
public bool IsContains(string Word, char searched_lit)
{
char[] lits = Word.ToCharArray();
foreach (char lit in lits)
{
if (lit == searched_lit)
{
return true;
}
}
return false;
}
public void Run()
{
int N = Convert.ToInt32(Console.ReadLine());
List<string> nums = new List<string>();
List<int> dual_number = new List<int>();
for (int i = 1; i <= N; i++)
{
nums.Add(Console.ReadLine());
}
foreach (string word in nums)
{
if (word.Length == 2)
{
if (IsContains(word, '4'))
{
dual_number.Add(Convert.ToInt32(word));
}
}
}
int result=0;
dual_number.ForEach(x => result += x);
Console.WriteLine(result / dual_number.Count);
Console.ReadKey();
}
}
}
Объяснение:
#include <iostream>
using namespace std;
int main()
{
setlocale(LC_ALL, "Rus");
int n, j;
cout << "введите длину массива ";cin >> n;
int* A = new int[n];
cout << "Введите массив " << endl;
for (int i = 0; i < n; i++) //ввод массива
{
cin >> A[i];
}
for (int i = n - 1; i >= 0; i--)
{
j = i;
while (A[j] == 0 && A[1 + j] != 0 && j + 1 < n)
{
int tmp = A[j + 1];
A[j + 1] = A[j];
A[j] = tmp;
j++;
}
}
cout << "новый массив ";
for (int i = 0; i < n; i++)
{
cout << A[i]<<" ";
}
delete[] A;
return 0;
}