From 12f648998464e7820e2be633e4d999c285047bce Mon Sep 17 00:00:00 2001 From: Oskar Date: Wed, 9 Oct 2024 16:55:14 +0200 Subject: more --- 9p13.cpp | 2 +- 9p14.cpp | 28 ++++++++++++++++++++++++++++ 9p15.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 9p16.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 9p17.cpp | 16 ++++++++++++++++ 5 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 9p14.cpp create mode 100644 9p15.cpp create mode 100644 9p16.cpp create mode 100644 9p17.cpp diff --git a/9p13.cpp b/9p13.cpp index 781f1e4..12ca7e9 100644 --- a/9p13.cpp +++ b/9p13.cpp @@ -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 +#include +#include + +/* + * + * 9.14 + * + * + */ + +int main () { + + std::list lcp = {"a","asjksd","skjk333","dkowdkjfdkjfd","wwdfsd", "eeeeeeee", "1253653463"}; + std::vector 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 +#include +#include +/* + * + * 9.15 + * + * + */ + +int main () { + + std::vector v1; + std::vector 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 +#include +#include + +/* + * + * 9.16 + * + * + */ + +int main () { + + std::vector v1; + std::list 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 and a std::vector + return 0; +} -- cgit v1.2.3