From 6d7b9aae2f3f6a83cf0517ae96f3258e7191ce56 Mon Sep 17 00:00:00 2001 From: Omar Magdy Date: Wed, 4 May 2022 20:02:33 +0200 Subject: Solved some new problems --- StringTask.cpp | 20 ++++++++++++++++++++ python/StringTask.py | 14 ++++++++++++++ recursionTest.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 StringTask.cpp create mode 100755 python/StringTask.py create mode 100644 recursionTest.cpp diff --git a/StringTask.cpp b/StringTask.cpp new file mode 100644 index 0000000..74d4635 --- /dev/null +++ b/StringTask.cpp @@ -0,0 +1,20 @@ +#include + +using namespace std; + +int main() { + ios::sync_with_stdio(false); + cin.tie(0); + string s; + cin >> s; + string vowels = "aeiouy"; + set st(vowels.begin(), vowels.end()); + string ans = ""; + for (char ch : s) { + if (!st.count(tolower(ch))) { + ans += "." + string(1, tolower(ch)); + } + } + cout << ans << '\n'; + return 0; +} diff --git a/python/StringTask.py b/python/StringTask.py new file mode 100755 index 0000000..9723550 --- /dev/null +++ b/python/StringTask.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 + +s = input() +ans = "" +vowels = "aeouiy" + +for ch in s: + if ch.lower() in vowels: + s = s.replace(ch, "") +for ch in s: + ans += "." + ch.lower() + +print(ans) + diff --git a/recursionTest.cpp b/recursionTest.cpp new file mode 100644 index 0000000..ae3ab32 --- /dev/null +++ b/recursionTest.cpp @@ -0,0 +1,47 @@ +#include + +using namespace std; + +string ans; + +bool solve(vector v,int idx, int target, int sum, string opts) { + if(idx == v.size() - 1) { + if(sum == target){ + ans = opts; + return true; + } + return false; + } + else { + int nxt = idx + 1; + bool plus = solve(v, nxt, target, sum + v[nxt],opts + "+"); + bool minus = solve(v, nxt, target, sum - v[nxt], opts + "-"); + bool mult = solve(v, nxt, target, sum * v[nxt], opts + "*"); + bool div = solve(v, nxt, target, sum / v[nxt], opts + "/"); + return plus || minus || mult || div; + } + +} + +int main() { + int n, target; + cin >> n >> target; + vector v(n); + string opts = ""; + for(int &x : v) { + cin >> x; + } + if(solve(v, 0, target, v[0], opts)) { + for(int i = 0; i < v.size(); i++) { + if (i == v.size() - 1) { + cout << v[i]; + } + else { + cout << v[i] << " " << ans[i] << " "; + } + } + cout << '\n'; + } + + return 0; +} -- cgit v1.2.3