#include<iostream>
#include<iomanip> // для красивого вывода матрицы
using namespace std;
int main()
{
short Array1[7][7];
short Array2[49];
srand(time(NULL));
size_t temp_y{ 0 }, temp_x{ 0 }; // переменные (беззнакового типа)
// для перемещения по матрице при заполнении
for (auto x = 0; x < 49; x++)
{
Array2[x] = rand() % 100;
Array1[temp_x][temp_y++] = Array2[x];
if (temp_y == 7) // при заполнении крайнего столбца матрицы курсор перемещается
{
temp_x++; // на следующую строку
temp_y = 0; // в первый столбец
}
}
for (auto f = 0; f < 49; f++)
{
cout << setw(5) << Array2[f];
}
cout << endl << endl;
for (auto x = 0; x < 7; x++)
{
for (auto f = 0; f < 7; f++)
{
cout << setw(5) << Array1[x][f];
}
cout << endl;
}
return 0;
}
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
srand(unsigned(time(0)));
size_t n = 2 * rand() % 6 + 5, m = n;
int** array = new int* [n];
for (auto x = 0; x < n; x++)
{
array[x] = new int[m];
}
for (size_t x = 0; x < n; x++)
{
for (size_t y = 0; y < m; y++)
{
array[x][y] = 0;
}
}
unsigned h = 1; int p = 1;
for (size_t y = 0; y < m / 2; y++)
{
if (n - h == 0)
{
break;
}
for (size_t r = h; r < n - h; r++)
{
array[r][y] = p++;
}
h++;
}
for (size_t y = m / 2; y < m; y++)
{
if (n - h == 0)
{
break;
}
for (size_t r = h; r < n - h; r++)
{
array[r][y] = p++;
}
h--;
if (!h)
{
break;
}
}
for (size_t x = 0; x < n; x++)
{
for (size_t y = 0; y < m; y++)
{
cout << setw(5) << array[x][y];
}
cout << endl;
}
return 0;
}
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
int convertion(string& s)
{
if (s.size() > 8) // проверка на восьмибитность(?)
{
cerr << "invalid representation";
exit(-1);
}
int out{ 0 }; const int coefficient = 48;
for (size_t r = 0; r < s.size(); r++)
{
out += ((s[r]-coefficient) * pow(2, s.size()-1 - r));
}
return out;
}
int main()
{
ifstream Q("Digits.txt");
string temporary; // буферная строка
vector<int> array; // массив
while (Q >> temporary) // считывание из файла
{
array.push_back(convertion(temporary)); // помещение в массив чисел с проверкой
}
// вывод массива
for (const auto& v : array)
{
cout<< v<<endl;
}
Q.close();
int max1 = INT16_MIN, max2 = INT16_MIN, min1 = INT16_MAX, min2 = INT16_MAX;
// поиск первых минимума и максимума
for (const auto& v : array)
{
if (v > max1)
{
max1 = v;
}
else if (v < min1)
{
min1 = v;
}
}
// поиск вторых минимума и максимума
for (const auto& v : array)
{
if (v > max2&&v!=max1)
{
max2 = v;
}
else if (v < min2&&v!=min1)
{
min2 = v;
}
}
// вывод чисел:
cout<<"\n\nMAX:\n" << max1 << endl
<< max2 << endl
<<"\n\nMIN:\n" << min1 << endl
<< min2 << endl;
return 0;
}
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
ifstream Q("First.txt");
ofstream Z("Second.txt");
string temporary;
while (Q >> temporary) // извлекаем число из первого
{
Z << temporary << " "; // помещаем число во второй файл
}
Q.close(); Z.close(); return 0;
}
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
srand(unsigned(time(0)));
unsigned n, m;
cout << "Enter NxM:\n";
cout << "N: "; cin >> n;
cout << "M: "; cin >> m;
int** array = new int* [n];
for (unsigned f = 0; f < n; f++)
{
array[f] = new int[m + 1];
}
for (unsigned g = 0; g < n; g++)
{
for (unsigned f = 0; f < m; f++)
{
cout << "Enter array[" << g << "][" << f << "]: ";
cin >> array[g][f];
}
}
for (unsigned g = 0; g < n; g++)
{
for (unsigned f = 0; f < m; f++)
{
cout << setw(5) << array[g][f];
}
cout << endl;
}
cout << endl << endl;
unsigned add = m;
unsigned r = m - 1, w = m;
for (unsigned f = 0; f < n; f++)
{
for (auto l = 0; l < (m - add); l++)
{
swap(array[f][r--], array[f][w--]);
}
r = m - 1; w = m;
}
cout << "Enter odds column:\n";
for (unsigned g = 0; g < n; g++)
{
cout << "Array [" << g + 1 << "][" << add << "]: ";
cin >> array[g][add];
}
cout << endl << endl;
for (unsigned g = 0; g < n; g++)
{
for (unsigned f = 0; f < m + 1; f++)
{
cout << setw(5) << array[g][f];
}
cout << endl;
}
for (auto x = 0; x < n; x++)
{
delete[]array[x];
}
delete[] array; array = nullptr;
return 0;
}
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
template<class type>
class Formatted_Entrance
{
private:
type** array = nullptr;
unsigned n, m, add; bool pos;
int reptiloid() // защищенный ввод
{
string h; cin >> h;
try
{
return stoi(h);
}
catch (exception& u)
{
cerr << u.what() << endl;
exit(-1);
}
}
void initialize()
{
for (unsigned g = 0; g < n; g++)
{
for (unsigned f = 0; f < m; f++)
{
cout << "Enter array[" << g << "][" << f << "]: ";
cin >> array[g][f];
}
}
}
void adder()
{
cout << "Enter the number to place: ";
add = reptiloid();
if (pos == 0)
{
unsigned r = n - 1, w = n;
for (unsigned f = 0; f < m; f++)
{
for (auto l = 0; l < (n - add); l++)
{
swap(array[r--][f], array[w--][f]);
}
r = n - 1; w = n;
}
cout << "Enter odds row:\n";
for (unsigned g = 0; g < m; g++)
{
cout << "Array [" << add << "][" << g << "]: ";
cin >> array[add][g];
}
}
if (pos == 1)
{
unsigned r = m - 1, w = m;
for (unsigned f = 0; f < n; f++)
{
for (auto l = 0; l < (m - add); l++)
{
swap(array[f][r--], array[f][w--]);
}
r = m - 1; w = m;
}
cout << "Enter odds column:\n";
for (unsigned g = 0; g < n; g++)
{
cout << "Array [" << g << "][" << add << "]: ";
cin >> array[g][add];
}
}
}
void display(unsigned extra)
{
unsigned r1, r2;
if (pos == 0)
{
r1 = extra; r2 = m;
}
if (pos == 1)
{
r1 = n; r2 = extra;
}
for (unsigned g = 0; g < r1; g++)
{
for (unsigned f = 0; f < r2; f++)
{
cout << setw(5) << array[g][f];
}
cout << endl;
}
}
void lay(unsigned r)
{
initialize(); //заполение первоначальной матрицы
display(r - 1);// вывод ее на экран
cout << endl << endl;
adder(); // добавление строки или столбца
cout << endl << endl;
display(r);// вывод обновленной матрицы
}
public:
Formatted_Entrance()
{
cout << "Enter NxM:\n"; string choice;
cout << "N: ";
n = reptiloid();
cout << "M: ";
m = reptiloid();
cout << "What would you like to be extra - row or column?\n";
cin >> choice;
if (choice == "row")
{
pos = 0;
array = new type * [n + 1];
for (unsigned f = 0; f < n + 1; f++)
{
array[f] = new type[m];
}
lay(n + 1);
}
else if (choice == "column")
{
pos = 1;
array = new type * [n];
for (unsigned f = 0; f < n; f++)
{
array[f] = new type[m + 1];
}
lay(m + 1);
}
else
{
cout << "unexpected err";
exit(-1);
}
}
~Formatted_Entrance()
{
unsigned p1;
if (pos == 0)
{
p1 = n + 1;//после вставки строки
}
if (pos == 1)
{
p1 = n;//после вставки колонки
}
for (auto x = 0; x < p1; x++)
{
delete[] array[x];
}
delete[] array; array = nullptr;
}
};
int main()
{
srand(unsigned(time(0)));
Formatted_Entrance<string> obj;
return 0;
}
#include<iostream>
#include<string>
#include<sstream>
#include<iomanip>
using namespace std;
class PalindromCH
{
private:
bool palindrom(const string& d)
{
for (unsigned g = 0; g < d.size() / 2; g++)
{
if (d[g] != d[d.size() - g - 1])
{
return 0;
}
}
return 1;
}
unsigned counter(stringstream& c, string& d)
{
unsigned number{ 0 }; cout << endl;
cout << "Entered sequence of numbers:" << endl;
while (c >> d)
{
cout << setw(7) << d;
if (palindrom(d))
{
number++;
}
}
return number;
}
void check_digit(string& i)
{
cin >> i;
try
{
stod(i);
}
catch (exception& u)
{
cerr << u.what() << endl;
}
}
public:
void examination()
{
unsigned f, t{ 0 }; stringstream v; string inp;
cout << "Enter the number of elements: ";
check_digit(inp);
f = stoi(inp);
while (f--)
{
inp.clear();
cout << "Enter ["<< ++t <<"]: ";
check_digit(inp);
v << inp << " ";
}
cout << endl << endl << counter(v, inp);
cout << " palindroms have been founded" << endl;
}
};
int main()
{
PalindromCH text;
text.examination();
return 0;
}
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
void Shell(vector<short> &A)
{
unsigned n = A.size();
int d = n / 2;
int j = 0;
while (d > 0)
{
for (int i = 0; i < n - d; i++)
{
j = i;
while (j >= 0 && A[j] > A[j + d])
{
swap(A[j], A[j + d]);
j--;
}
}
d = d / 2;
}
}
int main()
{
srand(unsigned(time(0)));
unsigned n = rand() % 3 + 2, m = rand()%3+2;
cout <<"N: " << n << " M: " << m << endl << endl;
vector<vector<short>> Piligrim;
for (unsigned f = 0; f < n; f++)
{
vector<short> temporary;
for (unsigned g = 0; g < m; g++)
{
temporary.push_back(rand() % 1000);
}
Piligrim.push_back(temporary);
}
for (const auto& c : Piligrim)
{
for (const auto& y : c)
{
cout << setw(8) << y;
}
cout << endl;
}
cout << endl << endl;
cout << "Changed:";
cout << endl << endl;
vector<short> BUFFER;
for (auto u = 0; u < (n*m)/2; u++)
{
BUFFER.push_back(Piligrim[u/m][u-(u/m)*m]);
}
Shell(BUFFER);
for (auto u = 0; u < (n * m) / 2; u++)
{
Piligrim[u / m][u - (u / m) * n]= BUFFER[u];
}
BUFFER.clear();
for (auto u = (n * m) / 2; u <n*m ; u++)
{
BUFFER.push_back(Piligrim[u / m][u - (u / m) * m]);
}
Shell(BUFFER);
for (auto u = (n * m) / 2; u < n* m; u++)
{
Piligrim[u / m][u - (u / m) * m] = BUFFER[(n*m)-1-u];
}
BUFFER.clear();
for (const auto& c : Piligrim)
{
for (const auto& y : c)
{
cout << setw(8) << y;
}
cout << endl;
}
system("pause");
return 0;
}
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
srand(unsigned(time(0)));
unsigned n = 2*(rand() % 3 + 2);
vector<vector<int>>reptiloid;
for (unsigned j = 0; j < n; j++)
{
vector<int> ter;
for (unsigned c = 0; c < n; c++)
{
ter.push_back(rand() % 100);
}
reptiloid.push_back(ter);
}
for (const auto& v : reptiloid)
{
for (const auto& b : v)
{
cout << setw(7) << b;
}
cout << endl;
}
cout << endl << endl << endl;
vector<int> barge;
for (unsigned u1 = 0; u1 < (n/2); u1++)
{
for (unsigned u2 = 0; u2 < n/2; u2++)
{
if ((u1 + u2) >= (n / 2) - 1)
{
barge.push_back(reptiloid[u1][u2]);
}
}
cout << endl;
}
sort(barge.begin(), barge.end());
auto c = barge.begin();
for (unsigned u1 = 0; u1 < n / 2; u1++)
{
for (unsigned u2 = 0; u2 < n / 2; u2++)
{
if ((u1 + u2) >= (n / 2) - 1)
{
reptiloid[u1][u2] = (*c);
c++;
}
}
cout << endl;
}
cout << "Changed:" << endl << endl;
for (const auto& v : reptiloid)
{
for (const auto& b : v)
{
cout << setw(7) << b;
}
cout << endl;
}
return 0;
}
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
string namefile; cout << "Enter name of file: ";
cin >> namefile;
namefile += ".txt"; cout << endl;
ifstream Q(namefile); string temporary;
double summary{ 0 }; unsigned items{ 0 };
while (Q >> temporary)
{
summary += stod(temporary);
items++;
cout << "Value: " << stod(temporary);
cout << endl<< "Current summary: " << summary << endl;
cout << endl<<endl<<endl; temporary.clear();
}
cout << "We have reached the edge." << endl << endl;
cout << items << " items have just read" << endl << endl;
cout << "Summary: " << summary << endl << endl;
cout << "Average: " << (summary / items);
return 0;
}
#include<iostream>
#include<string>
#include<vector>
#include<sstream>
using namespace std;
void reptiliod(string &two, vector<string>& replacements,
vector<string>&patterns, unsigned&f, string&templ)
{
stringstream inp; inp << two; two.clear();
while (inp >> templ)
{
if (templ == patterns[f])
{
two += replacements[f++] + " ";
}
else
{
two += templ + " ";
}
}
}
int main()
{
string two; cout << "Enter input string: ";
getline(cin, two);
vector<string> patterns;
cout << "Enter the words you need to erase:" << endl;
bool a = 0; unsigned f = 0; string templ;
do
{
cout << "[" << f++ << "] word: "; cin >> templ;
patterns.push_back(templ);
cout << "Do you want to finish? "; cin >> templ;
if (templ == "YES" || templ == "yes")
{
a = 1;
}
templ.clear();
} while (!a); f = 0; a = 0;
vector<string> replacements;
cout << "Enter the words you need to insert:" << endl;
do
{
cout << "[" << f++ << "] word: "; cin >> templ;
replacements.push_back(templ);
cout << "Do you want to finish? "; cin >> templ;
if (templ == "YES" || templ == "yes")
{
a = 1;
}
templ.clear();
} while (!a); f = 0; templ.clear();
reptiliod(two,replacements,patterns,f,templ);
cout<< endl << two << endl;
return 0;
}
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<short> myVector = { 1, 3, 10, 20, 13, 15, 4, 7, 9 , 18, 19, 1, 3 };
for (auto b = myVector.begin(); b!=myVector.end();)
{
if ((*b) > 9)
{
b = myVector.erase(b);
}
else b++;
}
for (const auto s : myVector)
{
cout << s << " ";
}
return 0;
}
#include<iostream>
#include<set>
#include<string>
using namespace std;
string generate()
{
unsigned n = rand() % 10 + 5; string t;
for (int j = 0; j < n; j++)
{
t += rand() % 25 + 97;
}
return t;
}
int main()
{
set<string> reptiloid; srand(unsigned(time(0)));
unsigned N = 10, f = rand()%10;
for (auto c = 0; c < N; c++)
{
reptiloid.insert(generate());
}
for (const auto& s : reptiloid)
{
cout << s << endl;
}
unsigned g = 0;
for (set<string>::iterator s = reptiloid.begin(); s!=reptiloid.end();s++)
{
if (g == f)
{
cout << endl << "selected: " << *s;
reptiloid.erase(s);
break;
}
g++;
}
cout << endl << endl;
for (const auto& s : reptiloid)
{
cout << s << endl;
}
cout << endl << endl;
return 0;
}
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
struct book
{
string name;
unsigned year;
unsigned circulation;
};
void sort(book* arr, book* array1, const unsigned& N);
unsigned kolvo(book* arr, const unsigned&N);
int main()
{
unsigned n, N; bool otkr;
setlocale(LC_ALL, ""); book* arr = NULL;
cout << "ВЫБЕРИТЕ СПОСОБ ВВОДА. 0 - С КЛАВИАТУРЫ, 1 - ИЗ ФАЙЛА \n"; cin >> otkr;
if (!otkr)
{
cout << "ВВЕДИТЕ РАЗМЕР МАССИВА:\n";
cin >> N;
arr = new book[N];
for (int i = 0; i < N; i++)
{
cout << "ВВЕДИТЕ НАЗВАНИЕ КНИГИ:\n";
cin >> arr[i].name;
cout << "ВВЕДИТЕ ТИРАЖ:\n";
cin >> arr[i].circulation;
cout << "ВВЕДИТЕ ГОД \n";
cin >> arr[i].year;
};
for (int i = 0; i < N; i++)
{
cout << arr[i].name << " " << arr[i].circulation << " " << arr[i].year << endl;
};
}
else
{
ifstream knigi("TextFile1.txt");
knigi >> N;
arr = new book[N];
for (int i = 0; i < N; i++)
{
knigi >> arr[i].name >> arr[i].circulation >> arr[i].year;
}
};
if ((n = kolvo(arr, N)) == 0)
{
cout << "no matches";
return 0;
}
book* array1 = new book[n]; cout<<endl;
sort(arr, array1, N);
for (int i = 0; i < n; i++)
{
cout << "КНИГИ НАПЕЧАТАННЫЕ С 2000 ПО 2010 :" << arr[i].name << " " << arr[i].circulation << endl;
}
return 0;
}
void sort(book* arr, book* array1, const unsigned&N)
{
unsigned counter = 0;
for (auto i = 0; i < N; i++)
{
if ((arr[i].year > 1999) && (arr[i].year < 2011))
{
array1[counter].name = arr[i].name;
array1[counter++].circulation = arr[i].circulation;
}
}
}
unsigned kolvo(book* arr, const unsigned &N)
{
unsigned number = 0;
for (int i = 0; i < N; i++)
{
if (arr[i].year > 1999 && arr[i].year < 2011)
{
number++;
}
return(number);
}
}
#include <iostream>
#include<iomanip>
#include<string>
using namespace std;
bool inp(short& a)
{
string t; cin >> t; short b;
try
{
b = stoi(t);
}
catch (exception)
{
cout << "invalid input"; return 1;
}
a = b; return 0;
}
class TMatrix
{
private:
short n, m;
public:
short** arr = NULL;
bool set_size()
{
cout << "Enter number of columns: ";
if (inp(n) || n < 2)
{
return 1;
}
cout << "Enter number of rows: ";
if (inp(m) || m < 2)
{
return 1;
}
arr = new short* [n];
for (int i = 0; i < n; i++)
{
arr[i] = new short[m];
}
return 0;
};
void transpose()
{
for (auto i = 0; i < n; i++)
{
for (auto j = i + 1; j < n; j++)
{
swap(arr[i][j], arr[j][i]);
}
}
}
TMatrix(const TMatrix& obj)
{
n = obj.n; m = obj.m;
arr = new short* [n];
for (int i = 0; i < n; i++)
{
arr[i] = new short[m];
}
for (auto c = 0; c < n; c++)
{
for (auto v = 0; v < m; v++)
{
arr[c][v] = obj.arr[c][v];
}
}
}
void multiply(const TMatrix& obj)
{
cout << "matrix C:" << endl;
short reptiloid{ 0 };
for (auto i = 0; i < n; i++)
{
for (auto j = 0; j < obj.m; j++)
{
for (auto i1 = 0; i1 < m; i1++)
{
reptiloid += arr[i][i1] * obj.arr[i1][j];
}
cout << setw(4) << reptiloid; reptiloid = 0;
}
cout << endl;
}
}
TMatrix() { }
~TMatrix()
{
for (auto i = 0; i < n; i++)
{
delete arr[i];
}
};
void show()
{
cout << endl << endl;
for (auto c = 0; c < n; c++)
{
for (auto v = 0; v < m; v++)
{
cout << setw(7) << arr[c][v];
}
cout << endl;
}
cout << endl << endl;
}
bool set_elem()
{
for (auto i = 0; i < n; i++)
{
for (auto j = 0; j < m; j++)
{
cout << "Enter [" << i << "][" << j << "]: ";
if (inp(arr[i][j]))
{
cout << "invalid input";
return 1;
}
}
cout << endl;
}
return 0;
};
};
int main()
{
TMatrix Amas;
if (!Amas.set_size())
{
if (Amas.set_elem())
{
return 0;
}
}
Amas.show();
TMatrix Bmas = Amas;
Bmas.show();
Bmas.transpose();
Bmas.show();
cout << endl;
Amas.multiply(Bmas);
return 0;
}
#include<iostream>
#include<array>
#include<iomanip>
#include<Windows.h>
using namespace std;
int main()
{
srand(unsigned(time(0)));
array<array<char, 3>, 3> places;
for (auto s = 0; s < 9; s++)
{
places[s / 3][s - ((s / 3) * 3)] = '*';
}
bool end = 0; unsigned u1, u2; short f = 1; char g = 'a';
while (!end)
{
for (const auto& c : places)
{
for (const auto& x : c)
{
cout << setw(7) << x;
}
cout << endl;
}
cout << endl;
bool k = 0;
do
{
cout << "Enter coordinates:" << endl;
cout << "X: "; cin >> u1;
cout << "Y: "; cin >> u2;
if (!(u1 < 0 || u2 < 0 || u1>2 || u2>2))
{
if (f == 1 && places[u1][u2] == 'O')
{
k = 1; cout << "invalid input";
}
if (f == 0 && places[u1][u2] == 'X')
{
k = 1; cout << "invalid input";
}
}
else
{
k = 1; cout << "invalid input"; u1 = 0; u2 = 0;
}
Sleep(750);
system("cls");
} while (k);
if (f == 1)
{
places[u1][u2] = 'X';
f = 0;
}
else
{
places[u1][u2] = 'O';
f = 1;
}
if (g > 'e')
{
unsigned cr = 0, zer = 0;
for (const auto& c : places)
{
for (const auto& x : c)
{
if (x == 'O')
{
zer++;
}
if (x == 'X')
{
cr++;
}
}
if (cr == 3 || zer == 3)
{
end = 1;
break;
}
else
{
cr = 0; zer = 0;
}
}
for (auto s = 0; s < 3; s++)
{
for (auto x = 0; x < 3; x++)
{
if (places[x][s] == 'O')
{
zer++;
}
if (places[x][s] == 'X')
{
cr++;
}
}
if (cr == 3 || zer == 3)
{
end = 1;
break;
}
else
{
cr = 0; zer = 0;
}
}
for (auto s = 0; s < 3; s++)
{
if (places[s][s] == 'X')
{
cr++;
}
if (places[s][s] == 'O')
{
zer++;
}
}
if (cr == 3 || zer == 3)
{
end = 1;
break;
}
else
{
cr = 0; zer = 0;
}
for (auto s = 0; s < 3; s++)
{
if (places[s][2 - s] == 'X')
{
cr++;
}
if (places[s][2 - s] == 'O')
{
zer++;
}
}
if (cr == 3 || zer == 3)
{
end = 1;
break;
}
else
{
cr = 0; zer = 0;
}
}
if (g == 'i')
{
cout << "withdraw";
return 0;
}
system("cls");
g++;
}
system("cls");
for (const auto& c : places)
{
for (const auto& x : c)
{
cout << setw(7) << x;
}
cout << endl;
}
Sleep(1000);
system("cls");
cout << "Game over";
return 0;
}