aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Magdy <omar.professional8777@gmail.com>2022-05-29 00:05:50 +0200
committerOmar Magdy <omar.professional8777@gmail.com>2022-05-29 00:05:50 +0200
commit9997eb6fae11ca927df90c9712ce335b5a3f0cd0 (patch)
treed4d69eb4f068629d020ca02a04335986eea9a74b
parentaafb97c04f8b29d3e9e2e56b18614e73b5956125 (diff)
downloadcompetitive-programming-9997eb6fae11ca927df90c9712ce335b5a3f0cd0.tar.xz
competitive-programming-9997eb6fae11ca927df90c9712ce335b5a3f0cd0.zip
Added a new directory codechef which contains some problem I solved on codechef.com
-rw-r--r--DiffucltyRatingOrder.cpp23
-rw-r--r--EvenAndOdd.cpp25
-rw-r--r--InfinityStaircase.cpp24
-rw-r--r--PrimeOrNot.cpp16
-rw-r--r--TakeDiscountOrNot.cpp18
-rw-r--r--codechef/firstAndLastDigit.cpp19
-rw-r--r--codechef/hoopJump.cpp15
-rw-r--r--codechef/luckyFour.cpp22
-rw-r--r--codechef/motivations.cpp23
-rw-r--r--codechef/problemCategory.cpp23
-rw-r--r--codechef/programmingLanguages.cpp29
-rw-r--r--codechef/reverseTheNumber.cpp25
-rw-r--r--codechef/richieRich.cpp15
-rwxr-xr-xcodechef/smallestPossibleWholeNumberbin0 -> 17944 bytes
-rw-r--r--codechef/smallestPossibleWholeNumber.cpp19
-rw-r--r--codechef/sumOfDigits.cpp20
-rw-r--r--codechef/theTwoDishes.cpp15
-rwxr-xr-xcodechef/turnItbin0 -> 18120 bytes
-rw-r--r--codechef/turnIt.cpp16
-rw-r--r--codechef/twoDishes.cpp15
-rw-r--r--codechef/vaccineDates.cpp23
-rw-r--r--codechef/validTriangles.cpp15
22 files changed, 400 insertions, 0 deletions
diff --git a/DiffucltyRatingOrder.cpp b/DiffucltyRatingOrder.cpp
new file mode 100644
index 0000000..1ed740d
--- /dev/null
+++ b/DiffucltyRatingOrder.cpp
@@ -0,0 +1,23 @@
+#include<bits/stdc++.h>
+using namespace std;
+bool isIncreasing(vector<int> v) {
+ for(int i = 0; i < v.size() - 1; i++) {
+ if(v[i+1] < v[i]) {
+ return false;
+ }
+ }
+ return true;
+}
+
+
+int main() {
+ int tt;
+ cin >> tt;
+ while(tt--) {
+ int n;
+ cin >> n;
+ vector<int> v(n);
+ for(int &x : v) cin >> x;
+ cout << (isIncreasing(v) ? "YES" : "NO") << '\n';
+ }
+}
diff --git a/EvenAndOdd.cpp b/EvenAndOdd.cpp
new file mode 100644
index 0000000..3699c1b
--- /dev/null
+++ b/EvenAndOdd.cpp
@@ -0,0 +1,25 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+ int tt; cin >>tt;
+ while(tt--){
+ bool even = true, odd = true;
+ int n;
+ cin >> n;
+ vector<int> v(n);
+ for(int &x : v) cin >> x;
+ for(int i : v) {
+ if(i % 2 != 0) {
+ even = false;
+ }
+ }
+ for(int i : v) {
+ if(i % 2 == 0) {
+ odd = false;
+ }
+ }
+ cout << (!even && !odd ? "Mix" : even ? "Even" : "Odd") << endl;
+ }
+}
diff --git a/InfinityStaircase.cpp b/InfinityStaircase.cpp
new file mode 100644
index 0000000..aeb982a
--- /dev/null
+++ b/InfinityStaircase.cpp
@@ -0,0 +1,24 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+ int tt;
+ cin >> tt;
+ while(tt--) {
+ int n;
+ cin >> n;
+ n-=1;
+ if(n % 5 == 0) {
+ cout << (n / 5) * 2 << endl;
+ }
+ else{
+ if(n % 5 == 1 || n % 5 == 2 || n % 5 == 3) {
+ cout << ((n / 5) * 2) + 1 << endl;
+ }
+ else if(n % 5 == 4) {
+ cout << ((n / 5) * 2) + 2 << endl;
+ }
+ }
+ }
+}
diff --git a/PrimeOrNot.cpp b/PrimeOrNot.cpp
new file mode 100644
index 0000000..1995e85
--- /dev/null
+++ b/PrimeOrNot.cpp
@@ -0,0 +1,16 @@
+#include<bits/stdc++.h>
+using namespace std;
+
+int main() {
+ long long p;
+ bool flag = false;
+ cin >> p;
+ for(long long i = 2; i * i <= p; i++){
+ if(p % i == 0) {
+ flag = true;
+ break;
+ }
+ }
+ if(p == 1) flag = true;
+ cout << (flag ? "Not Prime" : "Prime") << endl;
+}
diff --git a/TakeDiscountOrNot.cpp b/TakeDiscountOrNot.cpp
new file mode 100644
index 0000000..3b4510b
--- /dev/null
+++ b/TakeDiscountOrNot.cpp
@@ -0,0 +1,18 @@
+#include<bits/stdc++.h>
+using namespace std;
+int main() {
+ int tt;
+ cin >> tt;
+ while(tt--) {
+ int n, x, y;
+ int s1 = x, s2 = 0;
+ cin >> n >> x >> y;
+ for(int i = 0; i < n; i++) {
+ int h;
+ cin >> h;
+ s2+=h;
+ s1+=max(0, h - y);
+ }
+ cout << (s1 < s2 ? "COUPON" : "NO COUPON") << '\n';
+ }
+}
diff --git a/codechef/firstAndLastDigit.cpp b/codechef/firstAndLastDigit.cpp
new file mode 100644
index 0000000..cdd4e49
--- /dev/null
+++ b/codechef/firstAndLastDigit.cpp
@@ -0,0 +1,19 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while (tt--) {
+ int x;
+ cin >> x;
+ int last = x % 10;
+ while (x > 9) {
+ x /= 10;
+ }
+ cout << x + last << endl;
+ }
+}
diff --git a/codechef/hoopJump.cpp b/codechef/hoopJump.cpp
new file mode 100644
index 0000000..c9bfef1
--- /dev/null
+++ b/codechef/hoopJump.cpp
@@ -0,0 +1,15 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main () {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while(tt--){
+ int n;
+ cin >> n;
+ cout << (n + 1) / 2 << '\n';
+ }
+}
diff --git a/codechef/luckyFour.cpp b/codechef/luckyFour.cpp
new file mode 100644
index 0000000..998b0d5
--- /dev/null
+++ b/codechef/luckyFour.cpp
@@ -0,0 +1,22 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while (tt--) {
+ int count = 0;
+ int x;
+ cin >> x;
+ while (x) {
+ int foo = x % 10;
+ if(foo == 4) count++;
+ x /= 10;
+ }
+ cout << count << endl;
+ }
+}
+
diff --git a/codechef/motivations.cpp b/codechef/motivations.cpp
new file mode 100644
index 0000000..c015618
--- /dev/null
+++ b/codechef/motivations.cpp
@@ -0,0 +1,23 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while (tt--) {
+ int n, x;
+ cin >> n >> x;
+ int mx = 0;
+ while (n--) {
+ int s1, s2;
+ cin >> s1 >> s2;
+ if(s1 <= x) {
+ mx = max(mx, s2);
+ }
+ }
+ cout << mx << endl;
+ }
+}
diff --git a/codechef/problemCategory.cpp b/codechef/problemCategory.cpp
new file mode 100644
index 0000000..4eb7500
--- /dev/null
+++ b/codechef/problemCategory.cpp
@@ -0,0 +1,23 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main () {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while(tt--){
+ int x;
+ cin >> x;
+ if(x < 100) {
+ cout << "Easy" << '\n';
+ }
+ else if(x >= 100 && x < 200) {
+ cout << "Medium" << '\n';
+ }
+ else if(x >= 200 && x <= 300) {
+ cout << "Hard" << '\n';
+ }
+ }
+}
diff --git a/codechef/programmingLanguages.cpp b/codechef/programmingLanguages.cpp
new file mode 100644
index 0000000..4c45519
--- /dev/null
+++ b/codechef/programmingLanguages.cpp
@@ -0,0 +1,29 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main () {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while(tt--){
+ int a, b, a1, b1, a2, b2;
+ cin >> a >> b >> a1 >> b1 >> a2 >> b2;
+ int sum1 = a + b;
+ int diff1 = abs(a - b);
+ int sum2 = a1 + b1;
+ int diff2 = abs(a1 - b1);
+ int sum3 = a2 + b2;
+ int diff3 = abs(a2 - b2);
+ if(sum1 == sum2 && diff1 == diff2) {
+ cout << 1 << '\n';
+ }
+ else if(sum1 == sum3 && diff1 == diff3) {
+ cout << 2 << '\n';
+ }
+ else {
+ cout << 0 << '\n';
+ }
+ }
+}
diff --git a/codechef/reverseTheNumber.cpp b/codechef/reverseTheNumber.cpp
new file mode 100644
index 0000000..411f424
--- /dev/null
+++ b/codechef/reverseTheNumber.cpp
@@ -0,0 +1,25 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while (tt--) {
+ int sum = 0;
+ int x;
+ cin >> x;
+ int n = to_string(x).length() - 1;
+ int xR = 0;
+ while (x) {
+ int bar = x % 10;
+ xR += bar * pow(10, n);
+ n--;
+ x /= 10;
+ }
+ cout << xR << endl;
+ }
+}
+
diff --git a/codechef/richieRich.cpp b/codechef/richieRich.cpp
new file mode 100644
index 0000000..54b0331
--- /dev/null
+++ b/codechef/richieRich.cpp
@@ -0,0 +1,15 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main () {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while(tt--){
+ int a, b, x;
+ cin >> a >> b >> x;
+ cout << (b - a) / x << '\n';
+ }
+}
diff --git a/codechef/smallestPossibleWholeNumber b/codechef/smallestPossibleWholeNumber
new file mode 100755
index 0000000..45b750b
--- /dev/null
+++ b/codechef/smallestPossibleWholeNumber
Binary files differ
diff --git a/codechef/smallestPossibleWholeNumber.cpp b/codechef/smallestPossibleWholeNumber.cpp
new file mode 100644
index 0000000..166fb9b
--- /dev/null
+++ b/codechef/smallestPossibleWholeNumber.cpp
@@ -0,0 +1,19 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main () {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while(tt--){
+ int x, y;
+ cin >> x >> y;
+ if(y != 0) {
+ cout << x % y << '\n';
+ } else {
+ cout << x << '\n';
+ }
+ }
+}
diff --git a/codechef/sumOfDigits.cpp b/codechef/sumOfDigits.cpp
new file mode 100644
index 0000000..f594465
--- /dev/null
+++ b/codechef/sumOfDigits.cpp
@@ -0,0 +1,20 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while (tt--) {
+ int sum = 0;
+ int x;
+ cin >> x;
+ while (x) {
+ sum += x % 10;
+ x /= 10;
+ }
+ cout << sum << endl;
+ }
+}
diff --git a/codechef/theTwoDishes.cpp b/codechef/theTwoDishes.cpp
new file mode 100644
index 0000000..f986e1f
--- /dev/null
+++ b/codechef/theTwoDishes.cpp
@@ -0,0 +1,15 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main () {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while(tt--){
+ int n, s;
+ cin >> n >> s;
+ cout << n - abs(s - n) << '\n';
+ }
+}
diff --git a/codechef/turnIt b/codechef/turnIt
new file mode 100755
index 0000000..cc62c99
--- /dev/null
+++ b/codechef/turnIt
Binary files differ
diff --git a/codechef/turnIt.cpp b/codechef/turnIt.cpp
new file mode 100644
index 0000000..926893a
--- /dev/null
+++ b/codechef/turnIt.cpp
@@ -0,0 +1,16 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main () {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while(tt--){
+ int u, v, a, s;
+ cin >> u >> v >> a >> s;
+ float vel = sqrt(u * u - 2 * a * s);
+ cout << (vel > v ? "NO" : "YES") << '\n';
+ }
+}
diff --git a/codechef/twoDishes.cpp b/codechef/twoDishes.cpp
new file mode 100644
index 0000000..2ed48f5
--- /dev/null
+++ b/codechef/twoDishes.cpp
@@ -0,0 +1,15 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main () {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while(tt--){
+ int n, fr, v, fi;
+ cin >> n >> fr >> v >> fi;
+ cout << (fr + fi >= n && v >= n ? "YES" : "NO") << '\n';
+ }
+}
diff --git a/codechef/vaccineDates.cpp b/codechef/vaccineDates.cpp
new file mode 100644
index 0000000..5c49a28
--- /dev/null
+++ b/codechef/vaccineDates.cpp
@@ -0,0 +1,23 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main () {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while(tt--){
+ int d, l, r;
+ cin >> d >> l >> r;
+ if(d >= l && d <= r) {
+ cout << "Take second dose now" << '\n';
+ }
+ else if(d > r) {
+ cout << "Too Late" << '\n';
+ }
+ else if(d < l) {
+ cout << "Too Early" << '\n';
+ }
+ }
+}
diff --git a/codechef/validTriangles.cpp b/codechef/validTriangles.cpp
new file mode 100644
index 0000000..3a048d1
--- /dev/null
+++ b/codechef/validTriangles.cpp
@@ -0,0 +1,15 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main () {
+ ios_base::sync_with_stdio(false);
+ cin.tie(NULL);
+ int tt;
+ cin >> tt;
+ while(tt--){
+ int a, b, c;
+ cin >> a >> b >> c;
+ cout << (a + b + c == 180 ? "YES" : "NO") << '\n';
+ }
+}