#include <iostream>
#include <fstream>
#include <random>
using namespace std;
int main()
{
ofstream fout("f.txt");
random_device rd;
mt19937 mer(rd());
for(int i = 0 ; i < 10 ; ++i)
fout << mer() << ' ';
fout.close();
ofstream gout("g.txt");
ifstream fin("f.txt");
for (int i = 0 ; i < 10 ; ++i)
unsigned int temp;
fin >> temp;
if( temp % 2 == 0 )
gout << temp << ' ';
cout << temp << ' ';
}
fin.close();
gout.close();
===== PascalABC.NET =====
procedure SortShell<T>(a: array of T);
where T: IComparable<T>;
// сортировка по Шеллу
begin
var n := a.Length;
var d := n div 2;
while d > 0 do
var k := True;
while k do
k := False;
for var i := 0 to n - d - 1 do
if a[i].CompareTo(a[i + d]) > 0 then begin
Swap(a[i], a[i + d]);
k := True
end
end;
d := d div 2
var a := ArrRandom(10, -20, 20); a.Println;
SortShell(a); a.Println
end.
#include <iostream>
#include <fstream>
#include <random>
using namespace std;
int main()
{
ofstream fout("f.txt");
random_device rd;
mt19937 mer(rd());
for(int i = 0 ; i < 10 ; ++i)
fout << mer() << ' ';
fout.close();
ofstream gout("g.txt");
ifstream fin("f.txt");
for (int i = 0 ; i < 10 ; ++i)
{
unsigned int temp;
fin >> temp;
if( temp % 2 == 0 )
gout << temp << ' ';
cout << temp << ' ';
}
fin.close();
gout.close();
}
===== PascalABC.NET =====
procedure SortShell<T>(a: array of T);
where T: IComparable<T>;
// сортировка по Шеллу
begin
var n := a.Length;
var d := n div 2;
while d > 0 do
begin
var k := True;
while k do
begin
k := False;
for var i := 0 to n - d - 1 do
if a[i].CompareTo(a[i + d]) > 0 then begin
Swap(a[i], a[i + d]);
k := True
end
end;
d := d div 2
end
end;
begin
var a := ArrRandom(10, -20, 20); a.Println;
SortShell(a); a.Println
end.