aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--GoodString.cpp18
-rw-r--r--Odd-EvenIncrements.cpp59
-rw-r--r--PerfectlyBalancedString.cpp33
-rw-r--r--TokitsukazeAndAllZeroSequence.cpp38
-rwxr-xr-x[-rw-r--r--]python/CombinationLock.py0
-rw-r--r--python/DormsRoom.py7
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)