diff options
feat(Week11): Add solutions
1 files changed, 28 insertions, 0 deletions
| -rw-r--r-- | Week11/Exercise05.cpp | 28 |
diff --git a/Week11/Exercise05.cpp b/Week11/Exercise05.cpp new file mode 100644 index 0000000..5177003 --- /dev/null +++ b/Week11/Exercise05.cpp @@ -0,0 +1,28 @@ +#include <iostream> + +int main() { + const unsigned SIZE = 1024; + + char str[SIZE]; + std::cin.getline(str, SIZE, ':'); + double a, b; + std::cin >> a >> b; + + for (unsigned i = 0; str[i] != '\0' && str[i+2] != '\0'; i++) { + if (str[i] == 's' && + str[i+1] == 'u' && + str[i+2] == 'm') + { + std::cout << (a + b) << ' '; + } + else if (str[i] == 's' && + str[i+1] == 'u' && + str[i+2] == 'b') + { + std::cout << (a - b) << ' '; + } + } + std::cout << std::endl; + + return 0; +} |
