diff options
| author | Omar Magdy <omar.professional8777@gmail.com> | 2022-05-09 16:54:41 +0200 |
|---|---|---|
| committer | Omar Magdy <omar.professional8777@gmail.com> | 2022-05-09 16:54:41 +0200 |
| commit | 79d618f6b9a45d82023792140e70d271485cf005 (patch) | |
| tree | 55dd529dbea2327d0a23e80b78f8912e73633e6d | |
| parent | c7cecfca5337473def7f1c9adba208ab33a11c8e (diff) | |
| download | competitive-programming-79d618f6b9a45d82023792140e70d271485cf005.tar.xz competitive-programming-79d618f6b9a45d82023792140e70d271485cf005.zip | |
Added some new problems
| -rw-r--r-- | GoodString.cpp | 18 | ||||
| -rw-r--r-- | Odd-EvenIncrements.cpp | 59 | ||||
| -rw-r--r-- | PerfectlyBalancedString.cpp | 33 | ||||
| -rw-r--r-- | TokitsukazeAndAllZeroSequence.cpp | 38 | ||||
| -rwxr-xr-x[-rw-r--r--] | python/CombinationLock.py | 0 | ||||
| -rw-r--r-- | python/DormsRoom.py | 7 |
6 files changed, 155 insertions, 0 deletions
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<bits/stdc++.h> + +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<bits/stdc++.h> +using namespace std; +bool isEvenOrOdd(vector<int> 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<int> v(n); + vector<int> vEven; + vector<int> 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 <algorithm> +#include<bits/stdc++.h> +using namespace std; +int main() { + int tt; + cin >> tt; + string s; + while(tt--){ + cin >> s; + bool ok = true; + do{ + cout << s << endl; + map<char, int> 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<bits/stdc++.h> +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<int> v(n); + map<int, int> 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 index 0ac8b2c..0ac8b2c 100644..100755 --- a/python/CombinationLock.py +++ b/python/CombinationLock.py 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) |
