Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
4 лабы 1,2,4,5,6,7,9.docx
Скачиваний:
5
Добавлен:
24.09.2019
Размер:
24.93 Кб
Скачать

4)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

namespace R2D2

{

class Program

{

static void blblbl(string B, string S)

{

Int32 i, n; Double a,b,c;

Console.Write("Введите количество элементов\nN=");

n = Convert.ToInt32(Console.ReadLine());

if (n <= 2) { Console.Write("error"); return; }

BinaryWriter J = new BinaryWriter

(File.Open(B, FileMode.Create));

BinaryWriter Y = new BinaryWriter

(File.Open(S, FileMode.Create));

if ((File.Exists(B)) && (File.Exists(S)))

{

Console.Write("введите элементы файла\n");

for (i = 0; i < n; i++)

{

c = Convert.ToDouble(Console.ReadLine());

J.Write(c);

}

J.Close();

BinaryReader F = new BinaryReader

(File.Open(B, FileMode.Open));

if (File.Exists(B))

{

a = F.ReadDouble();

b = F.ReadDouble();

for (i = 2; i < n; i++)

{

c = F.ReadDouble();

if ((b > a) && (b > c))

{

Y.Write(i);

Console.Write(i + " ");

}

a = b; b = c;

}

Y.Close();

F.Close();

return;

}

}

Console.Write("File Not Found");

}

static void Main(string[] args)

{

blblbl("C:\\a1.dat", "C:\\a2.dat");

Console.ReadKey();

}

}

}

9)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

namespace Lex

{

class Program

{

static void luther(string B, string S)

{

Int32 i, n,a,k=0,y=0;

Console.Write("Введите количество элементов\nN=");

n = Convert.ToInt32(Console.ReadLine());

if (n <= 0) { Console.Write("error"); return; }

BinaryWriter J = new BinaryWriter

(File.Open(B, FileMode.Create));

BinaryWriter Y = new BinaryWriter

(File.Open(S, FileMode.Create));

If ((File.Exists(b)) && (File.Exists(s)))

{

Console.Write("введите элементы файла\n");

for (i = 0; i < n; i++)

{

a = Convert.ToInt32(Console.ReadLine());

J.Write(a);

if (Math.Abs(a) > k) k = Math.Abs(a);

}

J.Close();

BinaryReader F = new BinaryReader

(File.Open(B, FileMode.Open));

If (File.Exists(b))

{

for (i = 0; i < n; i++)

{

a = F.ReadInt32();

Y.Write(a);

Console.Write("\n" + a);

if ((Math.Abs(a)==k)&&(y<3))

{

Y.Write(a);

Console.Write("\n" + 0);

y++;

}

}

Y.Close();

F.Close();

return;

}

}

Console.Write("File Not Found");

}

static void Main(string[] args)

{

luther("C:\\a1.dat","C:\\a2.dat");

Console.ReadKey();

}

}

}

2)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

namespace R2D2

{

class Program

{

static void Chewie(string B, string S)

{

Int32 i, n, j = 1, d = 0; Double a, b;

Console.Write("Введите количество элементов\nN=");

n = Convert.ToInt32(Console.ReadLine());

if (n <= 1) { Console.Write("error"); return; }

BinaryWriter J = new BinaryWriter

(File.Open(B, FileMode.Create));

BinaryWriter Y = new BinaryWriter

(File.Open(S, FileMode.Create));

If ((File.Exists(b)) && (File.Exists(s)))

{

Console.Write("введите элементы файла\n");

for (i = 0; i < n; i++)

{

a = Convert.ToDouble(Console.ReadLine());

J.Write(a);

}

J.Close();

BinaryReader F = new BinaryReader

(File.Open(B, FileMode.Open));

If (File.Exists(b))

{

b = F.ReadDouble();

for (i = 0; i < n - 1; i++)

{

a = F.ReadDouble();

if (a < b)

j++;

else

{

if (j > 1)

{

d++;

Y.Write(j);

Console.Write(j + " ");

}

j = 1;

}

b = a;

}

if (j > 1)

{ d++; Y.Write(j); Console.Write(j + " "); }

Y.Close();

F.Close();

if (d == 0) Console.Write("нет убывающих последовательностей"); return;

}

}

Console.Write("File not found");

}

static void Main(string[] args)

{

Chewie("C:\\a1.dat", "C:\\a2.dat");

Console.ReadKey();

}

}

}

6)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

namespace R2D2

{

class Program

{

static void bonduelle(string B, string S)

{

Int32 i, n,a; Int32[] b=new Int32[15];

Console.Write("Введите количество элементов\nN=");

n = Convert.ToInt32(Console.ReadLine());

if (n <= 0) { Console.Write("error"); return; }

BinaryWriter J = new BinaryWriter

(File.Open(B, FileMode.Create));

BinaryWriter Y = new BinaryWriter

(File.Open(S, FileMode.Create));