seminar05

master
nihonium 2 years ago
parent 1d5f2cac48
commit c01f40aca3
No known key found for this signature in database
GPG Key ID: 0251623741027CFC

@ -7,7 +7,7 @@ using std::string, std::pair, std::cout, std::endl, std::vector;
template <typename T>
T maximum(const vector<T>& v) {
T max;
T max{};
for(int i = 0, size = v.size(); i < size; ++i) {
if (v[i] > max)
max = v[i];

@ -0,0 +1,22 @@
#include <vector>
#include <iostream>
#include <algorithm>
using std::cout, std::endl, std::vector, std::cin;
int main() {
size_t n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; ++i)
cin >> v[i];
vector<int>::iterator max = std::max_element(v.begin(), v.end());
std::sort(v.begin(), max);
std::sort(max, v.end());
std::reverse(max, v.end());
for (int i = 0; i < v.size(); ++i)
cout << v[i] << (i == v.size() - 1 ? "": " ");
cout << endl;
}

@ -0,0 +1,27 @@
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using std::cout, std::endl, std::string, std::vector;
void string_vector_reverse(vector<string>& sv) {
std::for_each(sv.begin(), sv.end(), [](string& s){ std::reverse(s.begin(), s.end()); });
std::reverse(sv.begin(), sv.end());
}
int main() {
vector<string> sv1 {"cat", "dog", "mouse", "elephant"};
vector<string> sv2 {"a", "bc"};
string_vector_reverse(sv1);
string_vector_reverse(sv2);
for (int i = 0; i < sv1.size(); ++i)
cout << sv1[i] << (i == sv1.size() - 1 ? "" : " ");
cout << endl;
for (int i = 0; i < sv2.size(); ++i)
cout << sv2[i] << (i == sv2.size() - 1 ? "" : " ");
cout << endl;
}

@ -0,0 +1,18 @@
#include <algorithm>
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <cctype>
using std::string, std::cin, std::cout, std::endl;
bool strIsUpper(const string& s) {
return std::accumulate(s.begin(), s.end(), true, [](bool res, char c) {return res && (!isalpha(c) || isupper(c)); });
}
int main() {
string s;
getline(cin, s);
cout << strIsUpper(s) << endl;
}

@ -0,0 +1,22 @@
#include <iostream>
#include <algorithm>
#include <string>
#include <string_view>
#include <cctype>
using std::cout, std::endl, std::string, std::string_view;
bool isIdentifier(string_view sv) {
bool is = true;
if (!(std::isalpha(sv[0]) || sv[0] == '_'))
return false;
if (std::all_of(sv.begin(), sv.end(), [](const char c){ return isalpha(c) || isdigit(c) || c == '_' ;}))
return true;
return false;
}
int main() {
string s;
getline(std::cin, s);
cout << isIdentifier(s) << endl;
}

@ -0,0 +1,18 @@
#include <iostream>
#include <string>
#include <algorithm>
using std::cout, std::string, std::endl;
void move_spaces(string& s) {
std::stable_sort(s.begin(), s.end(), [](const char& a, const char& b){ return (b == ' '); });
}
int main() {
string s;
std::getline(std::cin, s);
move_spaces(s);
// So we can see spaces
cout << s << "###" << endl;
}