This commit is contained in:
Andrew 2019-11-19 00:19:04 +07:00
parent 4744ebb565
commit deba2fdcf0
5 changed files with 160 additions and 8 deletions

View file

@ -4,6 +4,7 @@
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include <cmath> #include <cmath>
#include <limits>
using namespace std; using namespace std;
@ -30,9 +31,9 @@ int main() {
return 1; return 1;
} }
vector<float> v = read_vec(inf); vector<float> v = read_vec(inf);
size_t index = -1; size_t index = 0;
float smallest = 1e38f; float smallest = v[index];
for (size_t i = 0; i < v.size(); i++) { for (size_t i = 1; i < v.size(); i++) {
if (nearest_int_dist(v[i]) < smallest) { if (nearest_int_dist(v[i]) < smallest) {
smallest = nearest_int_dist(v[i]); smallest = nearest_int_dist(v[i]);
index = i; index = i;

View file

@ -3,15 +3,20 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <string> #include <string>
#define MAX_STRING 5000
using namespace std; using namespace std;
string get_short_name(const string &full_name) { string get_short_name(const string &full_name) {
char s[MAX_STRING], n[MAX_STRING], f[MAX_STRING], out[MAX_STRING]; string out[3];
sscanf(full_name.c_str(), "%s %s %s", s, n, f); int i = 0;
sprintf(out, "%s %c.%c.", s, n[0], f[0]); for (char c : full_name) {
return string(out); if (c == ' ') {
i++;
continue;
}
out[i] += c;
}
return out[0] + " " + out[1][0] + "." + out[2][0] + ".";
} }
void read_string(istream &reader, string &where, char delimiter) { void read_string(istream &reader, string &where, char delimiter) {
@ -31,6 +36,7 @@ int main() {
while (!inf.eof()) { while (!inf.eof()) {
string s; string s;
read_string(inf, s, '\n'); read_string(inf, s, '\n');
if (s.size() < 2) continue;
cout << get_short_name(s) << endl; cout << get_short_name(s) << endl;
} }
return 0; return 0;

View file

@ -0,0 +1,41 @@
// pb_z11_31.cpp
// Горбацевич Андрей
#include <iostream>
using namespace std;
int **read_matrix(size_t rows, size_t cols);
void print_matrix(int **matrix, size_t rows, size_t cols);
int **make2d(size_t nrows, size_t ncols, int val);
int main() {
size_t rows, cols;
int filler;
cout << "rows, cols, filling_val >>>";
cin >> rows >> cols >> filler;
int **matrix = make2d(rows, cols, filler);
print_matrix(matrix, rows, cols);
return 0;
}
int **make2d(size_t nrows, size_t ncols, int val) {
int **out = new int*[nrows];
for(size_t i = 0; i < nrows; i++) {
int *row = new int[ncols];
for(size_t j = 0; j < ncols; j++) {
*(row + j) = val;
}
*(out + i) = row;
}
return out;
}
void print_matrix(int **matrix, size_t rows, size_t cols) {
for(size_t i = 0; i < rows; i++) {
for(size_t j = 0; j < cols; j++) {
cout << *(*(matrix + i) + j) << " ";
}
cout << endl;
}
}

View file

@ -0,0 +1,51 @@
// pb_z11_32.cpp
// Горбацевич Андрей
#include <iostream>
using namespace std;
int **read_matrix(size_t nrows, size_t ncols);
void print_matrix(int **matrix, size_t nrows, size_t ncols);
void fliplr(int **matrix, size_t nrows, size_t ncols);
int main() {
size_t rows, cols;
cout << "rows, cols >>>";
cin >> rows >> cols;
int **matrix = read_matrix(rows, cols);
cout << "Before:" << endl;
print_matrix(matrix, rows, cols);
fliplr(matrix, rows, cols);
cout << "After:" << endl;
print_matrix(matrix, rows, cols);
return 0;
}
int **read_matrix(size_t nrows, size_t ncols) {
int **out = new int*[nrows];
for(size_t i = 0; i < nrows; i++) {
int *row = new int[ncols];
for(size_t j = 0; j < ncols; j++) {
cin >> *(row + j);
}
*(out + i) = row;
}
return out;
}
void print_matrix(int **matrix, size_t nrows, size_t ncols) {
for(size_t i = 0; i < nrows; i++) {
for(size_t j = 0; j < ncols; j++) {
cout << *(*(matrix + i) + j) << " ";
}
cout << endl;
}
}
void fliplr(int **matrix, size_t nrows, size_t ncols) {
for(size_t i = 0; i < nrows; i++) {
for(size_t j = 0; j < ncols/2; j++) {
swap(*(*(matrix + i) + j), *(*(matrix + i) + ncols - j - 1));
}
}
}

View file

@ -0,0 +1,53 @@
// pb_z11_33.cpp
// Горбацевич Андрей
#include <iostream>
using namespace std;
int **read_matrix(size_t nrows, size_t ncols);
void print_matrix(int **matrix, size_t nrows, size_t ncols);
void transpose(int **matrix, size_t size);
int main() {
size_t size;
cout << "size >>>";
cin >> size;
int **matrix = read_matrix(size, size);
cout << "Before:" << endl;
print_matrix(matrix, size, size);
transpose(matrix, size);
cout << "After:" << endl;
print_matrix(matrix, size, size);
return 0;
}
int **read_matrix(size_t nrows, size_t ncols) {
int **out = new int*[nrows];
for(size_t i = 0; i < nrows; i++) {
int *row = new int[ncols];
for(size_t j = 0; j < ncols; j++) {
cin >> *(row + j);
}
*(out + i) = row;
}
return out;
}
void print_matrix(int **matrix, size_t nrows, size_t ncols) {
for(size_t i = 0; i < nrows; i++) {
for(size_t j = 0; j < ncols; j++) {
cout << *(*(matrix + i) + j) << " ";
}
cout << endl;
}
}
void transpose(int **matrix, size_t size) {
for(size_t i = 0; i < size; i++) {
for(size_t j = i; j < size; j++) {
int ri = *(*(matrix + i) + j);
int ci = *(*(matrix + j) + i);
swap(*(*(matrix + i) + j), *(*(matrix + j) + i));
}
}
}