Additions and updates in 1sem/PB

This commit is contained in:
Andrew 2019-12-05 16:02:59 +07:00
parent df67329dea
commit e9d7aa3900
7 changed files with 189 additions and 7 deletions

View file

@ -0,0 +1,43 @@
// pb_12_100.cpp
// Горбацевич Андрей
#include <iostream>
using namespace std;
void print_mtx(int **mtx, int w, int h);
int **generate_mtx(int n);
int main()
{
int n;
cout << "n >>>";
cin >> n;
int **mtx = generate_mtx(n);
print_mtx(mtx, n, n);
}
void print_mtx(int **mtx, int w, int h) {
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
cout << *(*(mtx + i) + j) << " ";
}
cout << endl;
}
cout << endl;
}
int **generate_mtx(int n) {
int **mtx = new int*[n];
for (int i = 0; i < n; i++) {
int *row = new int[n]();
int pos = n;
for (int j = -n+i; j < 0; j++) {
*(row + pos--) = abs(j);
}
for (int j = 0; pos >= 0; j++) {
*(row + pos--) = abs(j);
}
*(mtx + i) = row;
}
return mtx;
}

View file

@ -0,0 +1,50 @@
// pb_13_100.cpp
// Горбацевич Андрей
#include <iostream>
using namespace std;
void print_mtx(int **mtx, int w, int h, ostream &ost);
int **generate_mtx(int n);
int main()
{
ofstream fout("out.txt", ios::trunc);
if (!fout.is_open())
{
cerr << "Unable to open file" << endl;
return 1;
}
int n;
cout << "n >>>";
cin >> n;
int **mtx = generate_mtx(n);
print_mtx(mtx, n, n, fout);
}
void print_mtx(int **mtx, int w, int h, ostream &ost) {
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
ost << *(*(mtx + i) + j) << " ";
}
ost << endl;
}
ost << endl;
}
int **generate_mtx(int n) {
int **mtx = new int*[n];
for (int i = 0; i < n; i++) {
int *row = new int[n]();
int pos = n;
for (int j = -n+i; j < 0; j++) {
*(row + pos--) = abs(j);
}
for (int j = 0; pos >= 0; j++) {
*(row + pos--) = abs(j);
}
*(mtx + i) = row;
}
return mtx;
}

View file

@ -0,0 +1,35 @@
// pb_14_100.cpp
// Горбацевич Андрей
#include <iostream>
#include <fstream>
#include <string>
#define MAX_STRING 1000
using namespace std;
void my_task(istream &ist, ostream &ost);
int main()
{
ifstream inf("in.txt");
ofstream fout("out.txt", ios::trunc);
if (!inf.is_open() || !fout.is_open())
{
cerr << "Unable to open file" << endl;
return 1;
}
my_task(inf, fout);
}
void my_task(istream &ist, ostream &ost) {
while (!ist.eof() && ist.good()) {
string r;
getline(ist, r);
size_t i;
while ((i = r.find("YES")) != string::npos) {
r.replace(i, 3, "NO");
}
ost << r << endl;
}
}

View file

@ -41,16 +41,12 @@
* _`11`_ - [Практическая работа № 11 «Строки символов»](./11)
10. Двумерные массивы.
* _`z11`_ - [Z11. Задачи на двумерные массивы](./z11)
* _`12`_ - [Практическая работа № 12 «Двумерные массивы»](./12)
11. Текстовые файлы.
* _`z12`_ - [Z12. Задачи на текстовые файлы](./z12)
* _`13`_ - Практическая работа № 13 «Текстовые файлы»
* _`13`_ - [Практическая работа № 13 «Текстовые файлы»](./12)
* _`z13`_ - [Z13. Задачи на обработку текстов](./z13)
* _`14`_ - Практическая работа № 14 «Обработка текстов»
12. Двоичные файлы.
* _`z14`_ - [Z14. Задачи на двоичные файлы](./z14)
* _`15`_ - Практическая работа № 15 «Двоичные файлы»
* _`z15`_ - Z15. Задачи на обработку двоичных файлов
* _`16`_ - Практическая работа № 16 «Обработка двоичных файлов»
* _`14`_ - [Практическая работа № 14 «Обработка текстов»](./14)
> Два девятых пункта во втором разделе. Nuff said.

View file

@ -0,0 +1,28 @@
// pb_z15_43.cpp
// Горбацевич Андрей
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
void reverse_uchar(std::iostream &ost);
int main() {
fstream iof("out.bin", ios::in|ios::out|ios::binary);
if (!iof.is_open())
{
cerr << "Unable to open file" << endl;
return 1;
}
reverse_uchar(iof);
return 0;
}
void reverse_uchar(std::iostream &ost) {
unsigned char cval = UCHAR_MAX;
for (int i = 0; i <= cval; i++) {
ost << cval--;
}
}

View file

@ -0,0 +1,30 @@
// pb_z15_44.cpp
// Горбацевич Андрей
#include <iostream>
#include <fstream>
using namespace std;
void uchar_add(std::iostream &ost, unsigned char v);
int main() {
fstream iof("out.bin", ios::in|ios::out|ios::binary);
if (!iof.is_open())
{
cerr << "Unable to open file" << endl;
return 1;
}
unsigned char v;
cout << "Char >>>";
cin >> v;
uchar_add(iof, v);
return 0;
}
void uchar_add(std::iostream &ost, unsigned char v) {
while (!ost.eof() && ost.good()) {
unsigned int out = (unsigned char)ost.get() + v;
ost << (unsigned char)(out > 255? char(255) : char(out));
}
}

View file