[1sem]Fixed messed up sheeeeet
This commit is contained in:
parent
8fdc6de8c1
commit
b422362bcd
1 changed files with 35 additions and 60 deletions
|
|
@ -1,75 +1,50 @@
|
|||
// pb_15_100.cpp
|
||||
// pb_13_100.cpp
|
||||
// Горбацевич Андрей
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void text2bin(istream &ist, ostream &ost);
|
||||
void print_mtx(int **mtx, int w, int h, ostream &ost);
|
||||
int **generate_mtx(int n);
|
||||
|
||||
void my_task(istream &ist);
|
||||
|
||||
int main() {
|
||||
ifstream ifs("in.txt");
|
||||
ofstream ofs("out.bin", ios::trunc|ios::binary);
|
||||
if (!ifs.is_open())
|
||||
int main()
|
||||
{
|
||||
ofstream fout("out.txt", ios::trunc);
|
||||
if (!fout.is_open())
|
||||
{
|
||||
cerr << "Unable to open file" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
text2bin(ifs, ofs);
|
||||
my_task(ifs);
|
||||
|
||||
return 0;
|
||||
|
||||
int n;
|
||||
cout << "n >>>";
|
||||
cin >> n;
|
||||
int **mtx = generate_mtx(n);
|
||||
print_mtx(mtx, n, n, fout);
|
||||
}
|
||||
|
||||
void text2bin(istream &ist, ostream &ost) {
|
||||
int N, M;
|
||||
ist >> N >> M;
|
||||
ost << N << ' ' << M;
|
||||
for (int i = 0; i < N; i++) {
|
||||
ost << endl;
|
||||
for (int j = 0; j < M; j++) {
|
||||
int cv;
|
||||
ist >> cv;
|
||||
ost << cv << ' ';
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
void my_task(istream &ist) {
|
||||
ist.seekg(0, ios::beg);
|
||||
int k;
|
||||
cout << "k >>>";
|
||||
cin >> k;
|
||||
int N, M;
|
||||
ist >> N >> M;
|
||||
int **mtx = new int*[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
int *row = new int[M]();
|
||||
for (int j = 0; j < M; j++) {
|
||||
int cv;
|
||||
ist >> cv;
|
||||
*(row + j) = cv;
|
||||
}
|
||||
*(mtx + i) = row;
|
||||
}
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int j = 1; j < M; j++) {
|
||||
if (mtx[i][j-1] < mtx[i][j]) {
|
||||
bool flag = false;
|
||||
for (int v = 0; v < M; v++) {
|
||||
if (mtx[i][v] == k) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
cout << "Line " << i + 1 << " contains k(k==" << k << ")\n";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue