seminar05
This commit is contained in:
		
							parent
							
								
									1d5f2cac48
								
							
						
					
					
						commit
						c01f40aca3
					
				
					 7 changed files with 108 additions and 1 deletions
				
			
		|  | @ -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]; | ||||
|  |  | |||
							
								
								
									
										22
									
								
								seminar05_iterators/01_slide/main.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								seminar05_iterators/01_slide/main.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -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; | ||||
| } | ||||
							
								
								
									
										27
									
								
								seminar05_iterators/02_string_vector_reverse/main.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								seminar05_iterators/02_string_vector_reverse/main.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -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; | ||||
| } | ||||
							
								
								
									
										18
									
								
								seminar05_iterators/03_is_uppper/main.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								seminar05_iterators/03_is_uppper/main.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -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; | ||||
| } | ||||
							
								
								
									
										22
									
								
								seminar05_iterators/04_is_identifier/main.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								seminar05_iterators/04_is_identifier/main.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -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; | ||||
| } | ||||
							
								
								
									
										18
									
								
								seminar05_iterators/05_move_spaces/main.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								seminar05_iterators/05_move_spaces/main.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -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; | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								seminar05_iterators/homework_iterators.pdf
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								seminar05_iterators/homework_iterators.pdf
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in a new issue