Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Звіт Чуй.docx
Скачиваний:
6
Добавлен:
08.11.2019
Размер:
6.73 Mб
Скачать

Задача №3

Дана дійсна матриця розміром 20×30. Впорядкувати її рядки по зростанню сум їх елементів.

Реалізація на С#:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace pr273

{

class Program

{

static void Main(string[] args)

{

const int r = 4, s = 2;

double[,] mas = new double[r, s];

Random rand = new Random();

double temp;

for (int i = 0; i < r; i++)

{

for (int j = 0; j < s; j++)

{

mas[i, j] = double.Parse(Console.ReadLine());

}

}

for (int i = 0; i < r; i++)

{

for (int j = 0; j < s; j++)

{

Console.Write(mas[i,j]+" ");

}

Console.WriteLine();

}

double[] sum = new double[r];

for (int i = 0; i < r; i++)

sum[i]=0;

for (int i = 0; i < r; i++)

{

for (int j = 0; j < s; j++)

{

sum[i] += mas[i, j];

}

}

Console.WriteLine();

double max = 100000000;

double min = 0;

int im = 0;

for (int i=0; i<r; i++)

{

min = sum[i];

im = i;

for (int k = 0; k < r; k++)

{

if (min > sum[k])

{

min = sum[k];

im=k;

}

}

sum[im] = max;

for (int j = 0; j < s; j++)

{

Console.Write(mas[im, j] + " ");

}

Console.WriteLine();

}

Console.ReadKey();

}

}

}

Варіант 28

Задача №1

Дана послідовність слів, розділених комами, за останнім – крапка. Записати в файл слова, які мають більше 2 голосних літер.

Реалізація на C#:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Text.RegularExpressions;

using System.IO;

namespace pr281

{

class Program

{

static void Main(string[] args)

{

StreamWriter sw = new StreamWriter("D:\\text.txt");

string s=Console.ReadLine();

int val1=0, val2=0;

char c = s[0];

int curr = 0;

for (int i = 0; i < s.Length; i++)

{

if (s[i] == ',' || s[i] == '.')

{

val1 = val2;

val2 = i;

if (val1 != 0)

val1++;

if (curr >= 2)

{

for (int j = val1; j < val2; j++)

sw.Write(s[j]);

sw.WriteLine();

}

curr = 0;

}

else if (s[i] == 'a' || s[i] == 'e' || s[i] == 'u' || s[i] == 'i' || s[i] == 'o' || s[i] == 'y')

{

curr++;

}

}

sw.Close();

}

}

}

Реалізція на Delphi:

program Project2;

{$APPTYPE CONSOLE}

uses

SysUtils;

Var sw:textFile;

s:string;

val1, val2, curr, i:integer;

c:char;

begin

{ TODO -oUser -cConsole Main : Insert code here }

AssignFile(sw, 'f.txt');

ReWrite(sw);

ReadLn(s);

val1:=0; val2:=0;

c:= s[1];

curr := 0;

for i:= 1 to Length(s)

begin

if (s[i] = ',' or s[i] = '.') then

begin

val1 := val2;

val2 := i;

if (val1 <> 0)

inc(val1);

if (curr >= 2) then

begin

for (int j = val1; j < val2; j++)

Write(sw,s[j]);

WriteLn(sw);

end;

curr := 0;

end;

else if (s[i] == 'a' || s[i] == 'e' || s[i] == 'u' || s[i] == 'i' || s[i] == 'o' || s[i] == 'y')

begin

inc(curr);

end;

end;

CloseFile(sw);

end.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]