initial
This commit is contained in:
commit
2802401eee
79 changed files with 2650 additions and 0 deletions
61
1sem/programming basics/z10/28.cpp
Normal file
61
1sem/programming basics/z10/28.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
// pb_z10_28.cpp
|
||||
// Горбацевич Андрей
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
#define MAX_STR 5000
|
||||
using namespace std;
|
||||
|
||||
void rstrip(char*, const char*);
|
||||
char* get_string();
|
||||
void println_string(const char*);
|
||||
|
||||
int main() {
|
||||
char *s, *chars;
|
||||
cout << "Input string:" << endl;
|
||||
s = get_string();
|
||||
cout << "Input chars:" << endl;
|
||||
chars = get_string();
|
||||
cout << "String before:" << endl;
|
||||
println_string(s);
|
||||
rstrip(s, chars);
|
||||
cout << "String after:" << endl;
|
||||
println_string(s);
|
||||
}
|
||||
|
||||
void rstrip(char *s, const char *chars) {
|
||||
int rpad = 0;
|
||||
int i = (int)strlen(s)-1;
|
||||
bool found;
|
||||
do {
|
||||
found = false;
|
||||
char cc = *(s + i--);
|
||||
for (size_t j = 0; j < strlen(chars); j++) {
|
||||
if (cc == *(chars + j)) {
|
||||
rpad += 1;
|
||||
found = true;
|
||||
*(s + i+1) = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (found && i >= 0);
|
||||
}
|
||||
|
||||
char* get_string() {
|
||||
int c = 0;
|
||||
char *s = new char[MAX_STR];
|
||||
char ch;
|
||||
while ((ch = cin.get()) != '\n') {
|
||||
*(s + c++) = ch;
|
||||
}
|
||||
*(s + c) = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
void println_string(const char* s) {
|
||||
for (size_t i = 0; i < strlen(s); i++) {
|
||||
cout << *(s + i);
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
85
1sem/programming basics/z10/29.cpp
Normal file
85
1sem/programming basics/z10/29.cpp
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
// pb_z10_29.cpp
|
||||
// Горбацевич Андрей
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
#define MAX_STR 5000
|
||||
using namespace std;
|
||||
|
||||
void strip(char*, const char*);
|
||||
char* get_string();
|
||||
void println_string(const char*);
|
||||
|
||||
int main() {
|
||||
char *s, *chars;
|
||||
cout << "Input string:" << endl;
|
||||
s = get_string();
|
||||
cout << "Input chars:" << endl;
|
||||
chars = get_string();
|
||||
cout << "String before:" << endl;
|
||||
println_string(s);
|
||||
strip(s, chars);
|
||||
cout << "String after:" << endl;
|
||||
println_string(s);
|
||||
}
|
||||
|
||||
void strip(char *s, const char *chars) {
|
||||
int lpad = 0;
|
||||
int fi = 0;
|
||||
bool found;
|
||||
do {
|
||||
found = false;
|
||||
char cc = *(s + fi);
|
||||
for (size_t j = 0; j < strlen(chars); j++) {
|
||||
if (cc == *(chars + j)) {
|
||||
lpad += 1;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fi++;
|
||||
} while(found && fi >= 0);
|
||||
if(lpad > 0)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < strlen(s) - lpad; i++)
|
||||
{
|
||||
*(s + i) = *(s + i + lpad);
|
||||
}
|
||||
*(s + i) = '\0';
|
||||
}
|
||||
|
||||
int rpad = 0;
|
||||
int ei = (int)strlen(s)-1;
|
||||
do {
|
||||
found = false;
|
||||
char cc = *(s + ei--);
|
||||
for (size_t j = 0; j < strlen(chars); j++) {
|
||||
if (cc == *(chars + j)) {
|
||||
rpad += 1;
|
||||
found = true;
|
||||
*(s + ei + 1) = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (found && ei >= 0);
|
||||
}
|
||||
|
||||
char* get_string() {
|
||||
int c = 0;
|
||||
char *s = new char[MAX_STR];
|
||||
char ch;
|
||||
while ((ch = cin.get()) != '\n') {
|
||||
*(s + c++) = ch;
|
||||
}
|
||||
*(s + c) = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
void println_string(const char* s) {
|
||||
for (size_t i = 0; i < strlen(s); i++) {
|
||||
cout << *(s + i);
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
70
1sem/programming basics/z10/30.cpp
Normal file
70
1sem/programming basics/z10/30.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
// pb_z10_30.cpp
|
||||
// Горбацевич Андрей
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
#define MAX_STR 5000
|
||||
using namespace std;
|
||||
|
||||
size_t join(char*, size_t , const char*const*, size_t, const char*);
|
||||
char* get_string();
|
||||
char** get_string_list(size_t);
|
||||
void println_string(const char*);
|
||||
|
||||
int main() {
|
||||
size_t n_in;
|
||||
cout << "Count of strings >>>";
|
||||
cin >> n_in;
|
||||
cout << "Strings:" << endl;
|
||||
char **s_in = get_string_list(n_in+1);
|
||||
cout << "Joiner separator >>>";
|
||||
char *sep = get_string();
|
||||
cout << "Max length >>>";
|
||||
size_t len;
|
||||
cin >> len;
|
||||
char *s_out = new char[len];
|
||||
size_t f_len = join(s_out, len, s_in, n_in, sep);
|
||||
cout << "Joined string:" << endl;
|
||||
println_string(s_out);
|
||||
}
|
||||
|
||||
size_t join(char *s_out, size_t len, const char *const *s_in, size_t n_in, const char *sep) {
|
||||
string ps_out;
|
||||
ps_out += string(*(s_in + 1));
|
||||
for (size_t i = 2; i <= n_in; i++) {
|
||||
ps_out += string(sep) + string(*(s_in + i));
|
||||
}
|
||||
size_t mnl = min(len, ps_out.length());
|
||||
for (size_t i = 0; i < mnl; i++) {
|
||||
*(s_out + i) = ps_out.c_str()[i];
|
||||
}
|
||||
*(s_out + mnl) = '\0';
|
||||
return strlen(s_out);
|
||||
}
|
||||
|
||||
char** get_string_list(size_t count) {
|
||||
char **arr = new char*[count];
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
*(arr + i) = get_string();
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
char* get_string() {
|
||||
int c = 0;
|
||||
char *s = new char[MAX_STR];
|
||||
char ch;
|
||||
while ((ch = cin.get()) != '\n') {
|
||||
*(s + c++) = ch;
|
||||
}
|
||||
*(s + c) = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
void println_string(const char* s) {
|
||||
for (size_t i = 0; i < strlen(s); i++) {
|
||||
cout << *(s + i);
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue