diff options
author | Oskar <[email protected]> | 2024-10-09 16:55:14 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-10-09 16:55:14 +0200 |
commit | 12f648998464e7820e2be633e4d999c285047bce (patch) | |
tree | e596da0ae5017c139da37a88ffb4f9b595a7e03b | |
parent | e06a1fdebe095ad46b0607297f78077fccb11db1 (diff) |
more
-rw-r--r-- | 9p13.cpp | 2 | ||||
-rw-r--r-- | 9p14.cpp | 28 | ||||
-rw-r--r-- | 9p15.cpp | 41 | ||||
-rw-r--r-- | 9p16.cpp | 52 | ||||
-rw-r--r-- | 9p17.cpp | 16 |
5 files changed, 138 insertions, 1 deletions
@@ -24,6 +24,6 @@ int main () { std::cout << a << " "; } - std::cout << std::endl; + std::cout << std::endl; return 0; } diff --git a/9p14.cpp b/9p14.cpp new file mode 100644 index 0000000..f4344c3 --- /dev/null +++ b/9p14.cpp @@ -0,0 +1,28 @@ +#include <iostream> +#include <list> +#include <vector> + +/* + * + * 9.14 + * + * + */ + +int main () { + + std::list<const char*> lcp = {"a","asjksd","skjk333","dkowdkjfdkjfd","wwdfsd", "eeeeeeee", "1253653463"}; + std::vector<std::string> vs; + vs.assign(lcp.cbegin(), lcp.cend()); + for(auto &a : lcp) { + std::cout << a << " "; + } + + std::cout << std::endl; + for(auto &a : vs) { + std::cout << a << " "; + } + + std::cout << std::endl; + return 0; +} diff --git a/9p15.cpp b/9p15.cpp new file mode 100644 index 0000000..1a150b0 --- /dev/null +++ b/9p15.cpp @@ -0,0 +1,41 @@ +#include <iostream> +#include <vector> +#include <limits> +/* + * + * 9.15 + * + * + */ + +int main () { + + std::vector<int> v1; + std::vector<int> v2; + int in = 0; + std::cout << "v1" << std::endl; + for(int i = 0 ; i < 10 ; ++i) { + if(std::cin >> in) {} else { + std::cout << "Error: Wrong input." << std::endl; + return -1; + } + + v1.push_back(in); + } + + std::cout << "v2" << std::endl; + for(int i = 0 ; i < 10 ; ++i) { + if(std::cin >> in) {} else { + std::cout << "Error: Wrong input." << std::endl; + return -1; + } + + v2.push_back(in); + } + + if(v1 == v2) { + std::cout << "equal!" << std::endl; + } + + return 0; +} diff --git a/9p16.cpp b/9p16.cpp new file mode 100644 index 0000000..0ddc0e4 --- /dev/null +++ b/9p16.cpp @@ -0,0 +1,52 @@ +#include <iostream> +#include <vector> +#include <list> + +/* + * + * 9.16 + * + * + */ + +int main () { + + std::vector<int> v1; + std::list<int> v2; + int in = 0; + std::cout << "v1" << std::endl; + for(int i = 0 ; i < 10 ; ++i) { + if(std::cin >> in) {} else { + std::cout << "Error: Wrong input." << std::endl; + return -1; + } + + v1.push_back(in); + } + + std::cout << "v2" << std::endl; + for(int i = 0 ; i < 10 ; ++i) { + if(std::cin >> in) {} else { + std::cout << "Error: Wrong input." << std::endl; + return -1; + } + + v2.push_back(in); + } + + bool iseq = true; + auto v1beg = v1.cbegin(); + auto v2beg = v2.cbegin(); + for( ; v1beg != v1.cend() && v2beg != v2.cend() ; ++v1beg, ++v2beg) { + if(*v1beg != *v2beg) { + iseq = false; + break; + } + } + + if(iseq == true) { + std::cout << "equal!" << std::endl; + } + + return 0; +} diff --git a/9p17.cpp b/9p17.cpp new file mode 100644 index 0000000..76039f6 --- /dev/null +++ b/9p17.cpp @@ -0,0 +1,16 @@ + +/* + * + * 9.17 + * + * + */ + +int main () { + + // The elements contained must support the operator being used. In this case the less than (<) operator. + // The container itself must support the operator being used. (<) in this case. + // The container types must be the same. So for example you cannot use the operator between a list or a vector. + // The element type must be the same. You cannot use the operator between a std::vector<int> and a std::vector<double> + return 0; +} |