From 79d618f6b9a45d82023792140e70d271485cf005 Mon Sep 17 00:00:00 2001 From: Omar Magdy Date: Mon, 9 May 2022 16:54:41 +0200 Subject: Added some new problems --- GoodString.cpp | 18 ++++++++++++ Odd-EvenIncrements.cpp | 59 +++++++++++++++++++++++++++++++++++++++ PerfectlyBalancedString.cpp | 33 ++++++++++++++++++++++ TokitsukazeAndAllZeroSequence.cpp | 38 +++++++++++++++++++++++++ python/CombinationLock.py | 0 python/DormsRoom.py | 7 +++++ 6 files changed, 155 insertions(+) create mode 100644 GoodString.cpp create mode 100644 Odd-EvenIncrements.cpp create mode 100644 PerfectlyBalancedString.cpp create mode 100644 TokitsukazeAndAllZeroSequence.cpp mode change 100644 => 100755 python/CombinationLock.py create mode 100644 python/DormsRoom.py diff --git a/GoodString.cpp b/GoodString.cpp new file mode 100644 index 0000000..a0335fa --- /dev/null +++ b/GoodString.cpp @@ -0,0 +1,18 @@ +#include + +using namespace std; + +int main() { + int tt; cin >> tt; + int n; + while(tt--) { + cin >> n; + string s; + cin >> s; + for(int i = n - 1; i > 0; i--) { + int j = n - 2; + + } + } + +} diff --git a/Odd-EvenIncrements.cpp b/Odd-EvenIncrements.cpp new file mode 100644 index 0000000..dad00f5 --- /dev/null +++ b/Odd-EvenIncrements.cpp @@ -0,0 +1,59 @@ +#include +using namespace std; +bool isEvenOrOdd(vector v) { + bool even = false; + bool odd = false; + for(int x : v) { + if(x % 2 != 0) { + even = false; + break; + } + else{ + even = true; + } + } + for(int x : v) { + if(x % 2 == 0) { + odd = false; + break; + } + else{ + odd = true; + } + } + return odd || even; +} + +int main() { + int tt; + cin >> tt; + while(tt--) { + int n; + cin >> n; + vector v(n); + vector vEven; + vector vOdd; + for(int &x : v) { + cin >> x; + } + bool ok = isEvenOrOdd(v); + for(int x : v) { + vEven.push_back(x); + vOdd.push_back(x); + } + for(int i = 0; i < v.size(); i++) { + if(i % 2 == 0){ + vEven[i]++; + } + } + bool evenOp = isEvenOrOdd(vEven); + for(int i = 0; i < v.size(); i++) { + if(i % 2 != 0){ + vOdd[i]++; + } + } + bool oddOp = isEvenOrOdd(vOdd); + cout << (ok ? "YES" : (evenOp || oddOp ? "YES" : "NO")) << endl; + + } +} diff --git a/PerfectlyBalancedString.cpp b/PerfectlyBalancedString.cpp new file mode 100644 index 0000000..a83c3f4 --- /dev/null +++ b/PerfectlyBalancedString.cpp @@ -0,0 +1,33 @@ +#include +#include +using namespace std; +int main() { + int tt; + cin >> tt; + string s; + while(tt--){ + cin >> s; + bool ok = true; + do{ + cout << s << endl; + map mp; + for(auto ch : s) { + mp[ch]++; + } + int mx = 1; + int mn = 1; + for(auto x : mp){ + mx = max(mx, x.second); + mn = min(mn, x.second); + // cout << x.first << " " << x.second << endl; + } + if(mx - mn > 1) { + ok = false; + break; + } + } while(next_permutation(s.begin(), s.end())); + cout << (ok ? "YES" : "NO"); + cout << endl; + } +} + diff --git a/TokitsukazeAndAllZeroSequence.cpp b/TokitsukazeAndAllZeroSequence.cpp new file mode 100644 index 0000000..f83e44d --- /dev/null +++ b/TokitsukazeAndAllZeroSequence.cpp @@ -0,0 +1,38 @@ +#include +using namespace std; +int main() { + int tt; + cin >> tt; + while(tt--) { + int ansZ = 0; + bool duple = false; + bool zero = false; + int n; cin >> n; + vector v(n); + map mp; + for(auto &x : v) { + cin >> x; + if(x == 0) { + zero = true; + } + mp[x]++; + } + for(auto &p : mp) { + if(p.first == 0) { + ansZ+=p.second; + } + if(p.second > 1 && p.first != 0) { + duple = true; + } + } + if(zero) { + cout << n - ansZ << endl; + } + else if(duple){ + cout << n << endl; + } + else { + cout << n + 1 << endl; + } + } +} diff --git a/python/CombinationLock.py b/python/CombinationLock.py old mode 100644 new mode 100755 diff --git a/python/DormsRoom.py b/python/DormsRoom.py new file mode 100644 index 0000000..8dcfa75 --- /dev/null +++ b/python/DormsRoom.py @@ -0,0 +1,7 @@ +tt = int(input()) +n = int(input()) +s = input() +sp, chars = map(str, input()) +sp = int(sp) +idx = s[::-1].index(chars) +print(idx) -- cgit v1.2.3