From a0d7b8320a8996eee0ed957b79c3a882f8b47146 Mon Sep 17 00:00:00 2001 From: Omar Magdy Date: Sat, 30 Apr 2022 01:13:40 +0200 Subject: Added all current problems --- .gitignore | 1 + ...tters.cpp_691f772586c92182cd3ca9396098375f.prob | 1 + ...V_MOD.cpp_276b8c89d227db4a79dee1685b9c289c.prob | 1 + 08-03-2022(Div.3)/A | Bin 0 -> 18880 bytes 08-03-2022(Div.3)/A.cpp | 25 ++++++++ .../A_Deletions_of_Two_Adjacent_Letters | Bin 0 -> 18664 bytes .../A_Deletions_of_Two_Adjacent_Letters.cpp | 37 ++++++++++++ 08-03-2022(Div.3)/B | Bin 0 -> 17688 bytes 08-03-2022(Div.3)/B.cpp | 23 ++++++++ 08-03-2022(Div.3)/B_DIV_MOD.cpp | 23 ++++++++ 08-03-2022(Div.3)/C.cpp | 22 +++++++ 08-03-2022(Div.3)/D.cpp | 20 +++++++ 08-03-2022(Div.3)/E.cpp | 9 +++ 08-03-2022(Div.3)/tempCodeRunnerFile | Bin 0 -> 18640 bytes 21-04-2022(Div.4)/A | Bin 0 -> 17792 bytes 21-04-2022(Div.4)/A.cpp | 23 ++++++++ 21-04-2022(Div.4)/B | Bin 0 -> 47400 bytes 21-04-2022(Div.4)/B.cpp | 30 ++++++++++ 21-04-2022(Div.4)/E | Bin 0 -> 24728 bytes 21-04-2022(Div.4)/E.cpp | 25 ++++++++ 21-04-2022(Div.4)/F | Bin 0 -> 22712 bytes 21-04-2022(Div.4)/F.cpp | 7 +++ AlternatingCharachters.py | 12 ++++ CamelCase.cpp | 16 ++++++ Diagonal_Difference.cpp | 30 ++++++++++ Equalize_the_array.cpp | 19 +++++++ Flipping_bits.cpp | 16 ++++++ LisaWorkbook.cpp | 25 ++++++++ LonelyInteger.cpp | 12 ++++ Luck_balance.cpp | 37 ++++++++++++ MarcCakwalk.cpp | 18 ++++++ MinDiffInArray.cpp | 19 +++++++ RecursiveDigitSum.py | 14 +++++ SequenceEquation.cpp | 25 ++++++++ ThePowerSum.cpp | 36 ++++++++++++ chocolateFeast.cpp | 43 ++++++++++++++ chocolateFeastRevised.cpp | 19 +++++++ cutTheSticks.cpp | 63 +++++++++++++++++++++ cutTheSticksJoe.cpp | 21 +++++++ cutTheSticksRevised.cpp | 10 ++++ iceCreamParlor.cpp | 38 +++++++++++++ python/FindDigits.py | 21 +++++++ python/Kaprekar.py | 20 +++++++ 43 files changed, 761 insertions(+) create mode 100644 .gitignore create mode 100644 08-03-2022(Div.3)/.cph/.A_Deletions_of_Two_Adjacent_Letters.cpp_691f772586c92182cd3ca9396098375f.prob create mode 100644 08-03-2022(Div.3)/.cph/.B_DIV_MOD.cpp_276b8c89d227db4a79dee1685b9c289c.prob create mode 100755 08-03-2022(Div.3)/A create mode 100644 08-03-2022(Div.3)/A.cpp create mode 100755 08-03-2022(Div.3)/A_Deletions_of_Two_Adjacent_Letters create mode 100644 08-03-2022(Div.3)/A_Deletions_of_Two_Adjacent_Letters.cpp create mode 100755 08-03-2022(Div.3)/B create mode 100644 08-03-2022(Div.3)/B.cpp create mode 100644 08-03-2022(Div.3)/B_DIV_MOD.cpp create mode 100644 08-03-2022(Div.3)/C.cpp create mode 100644 08-03-2022(Div.3)/D.cpp create mode 100644 08-03-2022(Div.3)/E.cpp create mode 100755 08-03-2022(Div.3)/tempCodeRunnerFile create mode 100755 21-04-2022(Div.4)/A create mode 100644 21-04-2022(Div.4)/A.cpp create mode 100755 21-04-2022(Div.4)/B create mode 100644 21-04-2022(Div.4)/B.cpp create mode 100755 21-04-2022(Div.4)/E create mode 100644 21-04-2022(Div.4)/E.cpp create mode 100755 21-04-2022(Div.4)/F create mode 100644 21-04-2022(Div.4)/F.cpp create mode 100755 AlternatingCharachters.py create mode 100644 CamelCase.cpp create mode 100644 Diagonal_Difference.cpp create mode 100644 Equalize_the_array.cpp create mode 100644 Flipping_bits.cpp create mode 100644 LisaWorkbook.cpp create mode 100644 LonelyInteger.cpp create mode 100644 Luck_balance.cpp create mode 100644 MarcCakwalk.cpp create mode 100644 MinDiffInArray.cpp create mode 100644 RecursiveDigitSum.py create mode 100644 SequenceEquation.cpp create mode 100644 ThePowerSum.cpp create mode 100644 chocolateFeast.cpp create mode 100644 chocolateFeastRevised.cpp create mode 100644 cutTheSticks.cpp create mode 100644 cutTheSticksJoe.cpp create mode 100644 cutTheSticksRevised.cpp create mode 100644 iceCreamParlor.cpp create mode 100755 python/FindDigits.py create mode 100755 python/Kaprekar.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e935fd3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +binaries diff --git a/08-03-2022(Div.3)/.cph/.A_Deletions_of_Two_Adjacent_Letters.cpp_691f772586c92182cd3ca9396098375f.prob b/08-03-2022(Div.3)/.cph/.A_Deletions_of_Two_Adjacent_Letters.cpp_691f772586c92182cd3ca9396098375f.prob new file mode 100644 index 0000000..52ce51e --- /dev/null +++ b/08-03-2022(Div.3)/.cph/.A_Deletions_of_Two_Adjacent_Letters.cpp_691f772586c92182cd3ca9396098375f.prob @@ -0,0 +1 @@ +{"name":"A. Deletions of Two Adjacent Letters","group":"Codeforces - Codeforces Round #776 (Div. 3)","url":"https://codeforces.com/contest/1650/problem/0","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1646751197936,"input":"5\nabcde\nc\nabcde\nb\nx\ny\naaaaaaaaaaaaaaa\na\ncontest\nt","output":"YES\nNO\nNO\nYES\nYES"},{"id":1646853307171,"input":"1\nqjjyzcsjy\ns","output":""}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"ADeletionsOfTwoAdjacentLetters"}},"batch":{"id":"b130b25d-3d3d-4fce-9d67-8671131df21f","size":1},"srcPath":"/home/peng/test/Problem_Solving/08-03-2022(Div.3)/A_Deletions_of_Two_Adjacent_Letters.cpp"} \ No newline at end of file diff --git a/08-03-2022(Div.3)/.cph/.B_DIV_MOD.cpp_276b8c89d227db4a79dee1685b9c289c.prob b/08-03-2022(Div.3)/.cph/.B_DIV_MOD.cpp_276b8c89d227db4a79dee1685b9c289c.prob new file mode 100644 index 0000000..7eca9cb --- /dev/null +++ b/08-03-2022(Div.3)/.cph/.B_DIV_MOD.cpp_276b8c89d227db4a79dee1685b9c289c.prob @@ -0,0 +1 @@ +{"name":"B. DIV + MOD","group":"Codeforces - Codeforces Round #776 (Div. 3)","url":"https://codeforces.com/contest/1650/problem/B","interactive":false,"memoryLimit":256,"timeLimit":2000,"tests":[{"id":1646752657834,"input":"5\n1 4 3\n5 8 4\n6 10 6\n1 1000000000 1000000000\n10 12 8","output":"2\n4\n5\n999999999\n5"},{"id":1646833131418,"input":"1\n1 100 1","output":"100"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BDIVMOD"}},"batch":{"id":"18dc3187-28ba-42e4-adb6-b241bf475a66","size":1},"srcPath":"/home/peng/test/Problem_Solving/08-03-2022(Div.3)/B_DIV_MOD.cpp"} \ No newline at end of file diff --git a/08-03-2022(Div.3)/A b/08-03-2022(Div.3)/A new file mode 100755 index 0000000..a2ce84f Binary files /dev/null and b/08-03-2022(Div.3)/A differ diff --git a/08-03-2022(Div.3)/A.cpp b/08-03-2022(Div.3)/A.cpp new file mode 100644 index 0000000..741b57a --- /dev/null +++ b/08-03-2022(Div.3)/A.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +int main(){ + int tt; + cin >> tt; + while(tt--){ + string word; + char ch; + cin >> word; + cin >> ch; + int len = word.length(); + if(word[len/2 + 1] == ch){ + cout << word[len/2 + 1] << endl; + cout << ch << endl; + cout << "YES" << "\n"; + } + else{ + cout << "NO" << "\n"; + } + } + + return 0; +} \ No newline at end of file diff --git a/08-03-2022(Div.3)/A_Deletions_of_Two_Adjacent_Letters b/08-03-2022(Div.3)/A_Deletions_of_Two_Adjacent_Letters new file mode 100755 index 0000000..c79eb1d Binary files /dev/null and b/08-03-2022(Div.3)/A_Deletions_of_Two_Adjacent_Letters differ diff --git a/08-03-2022(Div.3)/A_Deletions_of_Two_Adjacent_Letters.cpp b/08-03-2022(Div.3)/A_Deletions_of_Two_Adjacent_Letters.cpp new file mode 100644 index 0000000..3f7daa2 --- /dev/null +++ b/08-03-2022(Div.3)/A_Deletions_of_Two_Adjacent_Letters.cpp @@ -0,0 +1,37 @@ +#include + +using namespace std; + +void findMultOcc(vector &indices, string str, char ch){ + for(int i = 0; i < str.length();i++){ + if(str[i] == ch){ + indices.push_back(i); + } + } +} + +string solve(vector indices){ + for(int i = 0; i < indices.size(); i++) + { + if(indices[i] >= 0 && indices[i] % 2 == 0){ + return "YES"; + } + } + return "NO"; +} + +int main(){ + int tt; + cin >> tt; + while(tt--){ + vector indices; + string word; + char ch; + cin >> word; + cin >> ch; + findMultOcc(indices, word, ch); + cout << solve(indices) << '\n'; + } + + return 0; +} diff --git a/08-03-2022(Div.3)/B b/08-03-2022(Div.3)/B new file mode 100755 index 0000000..b11c838 Binary files /dev/null and b/08-03-2022(Div.3)/B differ diff --git a/08-03-2022(Div.3)/B.cpp b/08-03-2022(Div.3)/B.cpp new file mode 100644 index 0000000..dd8bb54 --- /dev/null +++ b/08-03-2022(Div.3)/B.cpp @@ -0,0 +1,23 @@ +#include + +using namespace std; + +int modDiv(int r, int a){ + // law r % a == 0, return r-1 % a + r-1 /a, else return r % a + r /a; + if(r % a == 0){ + return (r-1) % a + (r-1)/a; + } + return r % a + r / a; +} + +int main(){ + int tt; + while(tt--){ + cout << "tt: " << tt; + int l, r, a; + cin >> l >> r >> a; + cout << modDiv(r, a); + } + + return 0; +} \ No newline at end of file diff --git a/08-03-2022(Div.3)/B_DIV_MOD.cpp b/08-03-2022(Div.3)/B_DIV_MOD.cpp new file mode 100644 index 0000000..f861b3b --- /dev/null +++ b/08-03-2022(Div.3)/B_DIV_MOD.cpp @@ -0,0 +1,23 @@ +#include + +using namespace std; + +int modDiv(int r, int a){ + // law r % a == 0, return r-1 % a + r-1 /a, else return r % a + r /a; + if(r % a == 0){ + return (r-1) % a + (r-1)/a; + } + return r % a + r / a; +} + +int main(){ + int tt; + cin >> tt; + while(tt--){ + int l, r, a; + cin >> l >> r >> a; + cout << modDiv(r, a) << endl; + } + + return 0; +} diff --git a/08-03-2022(Div.3)/C.cpp b/08-03-2022(Div.3)/C.cpp new file mode 100644 index 0000000..f63ebcd --- /dev/null +++ b/08-03-2022(Div.3)/C.cpp @@ -0,0 +1,22 @@ +#include + +using namespace std; + +int main(){ + int tt; + cin >> tt; + while(tt--){ + list ls; + int len; + int x; + cin >> len; + for(int i = 0; i < len; i++){ + cin >> x; + ls.push_back(x); + } + + + } + + return 0; +} \ No newline at end of file diff --git a/08-03-2022(Div.3)/D.cpp b/08-03-2022(Div.3)/D.cpp new file mode 100644 index 0000000..0572f03 --- /dev/null +++ b/08-03-2022(Div.3)/D.cpp @@ -0,0 +1,20 @@ +#include + +using namespace std; + +int solve() +{ + +} + +int main(){ + int tt; + cin >> tt; + while(tt--){ + + + } + + + return 0; +} diff --git a/08-03-2022(Div.3)/E.cpp b/08-03-2022(Div.3)/E.cpp new file mode 100644 index 0000000..2601cd5 --- /dev/null +++ b/08-03-2022(Div.3)/E.cpp @@ -0,0 +1,9 @@ +#include + +using namespace std; + +int main(){ + int tt; + + return 0; +} \ No newline at end of file diff --git a/08-03-2022(Div.3)/tempCodeRunnerFile b/08-03-2022(Div.3)/tempCodeRunnerFile new file mode 100755 index 0000000..9154686 Binary files /dev/null and b/08-03-2022(Div.3)/tempCodeRunnerFile differ diff --git a/21-04-2022(Div.4)/A b/21-04-2022(Div.4)/A new file mode 100755 index 0000000..58be759 Binary files /dev/null and b/21-04-2022(Div.4)/A differ diff --git a/21-04-2022(Div.4)/A.cpp b/21-04-2022(Div.4)/A.cpp new file mode 100644 index 0000000..35c326e --- /dev/null +++ b/21-04-2022(Div.4)/A.cpp @@ -0,0 +1,23 @@ +#include + +using namespace std; + +int main(){ + int tt, x; + cin >> tt; + while(tt--){ + cin >> x; + if(x >= 1900){ + cout << "Division 1" << '\n'; + } + else if(x >= 1600 && x <= 1899){ + cout << "Division 2" << '\n'; + } + else if(x >= 1400 && x <= 1599){ + cout << "Division 3" << '\n'; + } + else{ + cout << "Division 4" << '\n'; + } + } +} diff --git a/21-04-2022(Div.4)/B b/21-04-2022(Div.4)/B new file mode 100755 index 0000000..6a9b6ab Binary files /dev/null and b/21-04-2022(Div.4)/B differ diff --git a/21-04-2022(Div.4)/B.cpp b/21-04-2022(Div.4)/B.cpp new file mode 100644 index 0000000..d1b3e98 --- /dev/null +++ b/21-04-2022(Div.4)/B.cpp @@ -0,0 +1,30 @@ +#include + +using namespace std; + +auto solve(map m){ + for(auto x : m){ + if(x.second >= 3){ + return x.first; + } + } + return -1; +} + +int main(){ + int tt, x, n; + cin >> tt; + while(tt--){ + map frq; + vector v; + cin >> n; + for(int i = 0; i < n; i++){ + cin >> x; + frq[x]++; + } + // for(auto &x : frq){ + // v.push_back(x.second); + // } + cout << solve(frq) << endl; + } +} diff --git a/21-04-2022(Div.4)/E b/21-04-2022(Div.4)/E new file mode 100755 index 0000000..0e57ed4 Binary files /dev/null and b/21-04-2022(Div.4)/E differ diff --git a/21-04-2022(Div.4)/E.cpp b/21-04-2022(Div.4)/E.cpp new file mode 100644 index 0000000..7fac1a5 --- /dev/null +++ b/21-04-2022(Div.4)/E.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +int main(){ + int tt, n, count; + cin >> tt; + while(tt--){ + string str; + cin >> n; + count = 0; + vector v(n); + for(int i = 0; i < n; i++){ + cin >> v[i]; + } + for(int i = 0; i < v.size(); i++){ + for(int j = i+1; j < v.size()-1; j++){ + if(v[i][0] != v[j][0] || v[i][1] != v[j][1]){ + count++; + } + } + } + cout << count << endl; + } +} diff --git a/21-04-2022(Div.4)/F b/21-04-2022(Div.4)/F new file mode 100755 index 0000000..b87fe94 Binary files /dev/null and b/21-04-2022(Div.4)/F differ diff --git a/21-04-2022(Div.4)/F.cpp b/21-04-2022(Div.4)/F.cpp new file mode 100644 index 0000000..4ab1a8c --- /dev/null +++ b/21-04-2022(Div.4)/F.cpp @@ -0,0 +1,7 @@ +#include + +using namespace std; + +int main(){ + +} diff --git a/AlternatingCharachters.py b/AlternatingCharachters.py new file mode 100755 index 0000000..cb0a56c --- /dev/null +++ b/AlternatingCharachters.py @@ -0,0 +1,12 @@ +#!/bin/python3 +t = int(input()) +for i in range(t): + s = input() + count = 0 + for j in range(len(s) - 1): + # print(s[j] == s[j + 1]) + if s[j] == s[j + 1]: + count += 1 + print(count) + + diff --git a/CamelCase.cpp b/CamelCase.cpp new file mode 100644 index 0000000..bbcef3a --- /dev/null +++ b/CamelCase.cpp @@ -0,0 +1,16 @@ +#include + +using namespace std; + +int main() { + string s; + int count = 0; + cin >> s; + for(auto ch : s) { + if(isupper(ch)) { + count++; + } + } + cout << count + 1 << '\n'; + return 0; +} diff --git a/Diagonal_Difference.cpp b/Diagonal_Difference.cpp new file mode 100644 index 0000000..cb7c2f2 --- /dev/null +++ b/Diagonal_Difference.cpp @@ -0,0 +1,30 @@ +#include + +using namespace std; + +int main(){ + int n; + cin >> n; + vector v1(n); + vector> v2; + for(int i = 0; i < n; i++){ + for(auto &x : v1){ + cin >> x; + cout << "x: " << x << endl; + } + v2.push_back(v1); + } + int dg1 = 0, dg2 = 0; + for(int i = 0; i < n; i++){ + dg1+=v2[i][i]; + } + for(int i = 0; i < n; i++){ + dg2+=v2[i][n-i-1]; + } + cout << abs(dg2 - dg1) << endl; + + + return 0; + +} + diff --git a/Equalize_the_array.cpp b/Equalize_the_array.cpp new file mode 100644 index 0000000..89af0d8 --- /dev/null +++ b/Equalize_the_array.cpp @@ -0,0 +1,19 @@ +#include + +using namespace std; + +int main(){ + int n, x; + cin >> n; + map mp; + vector freq; + for(int i =0; i < n; i++){ + cin >> x; + mp[x]++; + } + for(auto x : mp){ + freq.push_back(x.second); + } + cout << n - *max_element(freq.begin(), freq.end()) << '\n'; + return 0; +} diff --git a/Flipping_bits.cpp b/Flipping_bits.cpp new file mode 100644 index 0000000..e06235b --- /dev/null +++ b/Flipping_bits.cpp @@ -0,0 +1,16 @@ +#include + + +using namespace std; + +int main(){ + int n, x=pow(2, 31) - 1; + cin >> n; + cout << n ^ x; + // 0 0 -> 1 -> 0 + // 1 1 -> 0 -> 1 + // 1 1 -> 0 -> 1 + // 1 1 -> 0 -> 0 + + return 0; +} diff --git a/LisaWorkbook.cpp b/LisaWorkbook.cpp new file mode 100644 index 0000000..6d8532c --- /dev/null +++ b/LisaWorkbook.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +int main() +{ + int n, k; + cin >> n >> k; + int pg = 1, res = 0; + for (int i = 0; i < n; i++) { + int np; + cin >> np; + for (int j = 1; j <= np ; j++) { + if (j == pg) { + res++; + } + if (j % k == 0 && j < np) { + pg++; + } + } + pg++; + } + cout << res << endl; + return 0; +} diff --git a/LonelyInteger.cpp b/LonelyInteger.cpp new file mode 100644 index 0000000..a5ce4a4 --- /dev/null +++ b/LonelyInteger.cpp @@ -0,0 +1,12 @@ +#include +using namespace std; +int main(){ + int n, x = 0, k; + cin >> n; + for(int i = 0; i < n; i++){ + cin >> k; + x ^= k; + } + cout << x; + return 0; +} diff --git a/Luck_balance.cpp b/Luck_balance.cpp new file mode 100644 index 0000000..403b53f --- /dev/null +++ b/Luck_balance.cpp @@ -0,0 +1,37 @@ +#include +using namespace std; +bool comparePair(pair p1, pair p2){ + if(p1.second >= p2.second && p1.first > p2.first){ + return true; + } + else { + return false; + } +} + +int main() { + int n, k, sum = 0, cn=0; + cin >> n >> k; + vector> vp(n); + for(auto &x : vp){ + cin >> x.first >> x.second; + } + sort(vp.begin(), vp.end(), comparePair); + cout << "-----------------------------------"; + cout << endl; + for(auto x : vp){ + cout << x.first << " " << x.second << endl; + } + for(int i = 0; i < n; i++){ + if(vp[i].second == 1){ + cn++; + } + if(cn != k - 1){ + cout << "vp[" << i << "]" << vp[i].first << endl; + sum+=vp[i].first; + } + } + sum -= vp[cn].first; + cout << sum << endl; + return 0; +} diff --git a/MarcCakwalk.cpp b/MarcCakwalk.cpp new file mode 100644 index 0000000..91884fd --- /dev/null +++ b/MarcCakwalk.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; +int main(){ + int n; + long sum; + cin >> n; + vector v(n); + for(auto &x : v){ + cin >> x; + } + sort(v.begin(), v.end()); + for(int i = 0; i < n; i++){ + cout << "v[" << i << "] = " << v[i] << " * " << "2^" << n - i - 1 << endl; + sum += v[i] * pow(2, n - i - 1); + } + cout << sum << endl; + return 0; +} diff --git a/MinDiffInArray.cpp b/MinDiffInArray.cpp new file mode 100644 index 0000000..5440d03 --- /dev/null +++ b/MinDiffInArray.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; +int main(){ + int n; + cin >> n; + vector v(n); + vector res; + for(auto &x : v){ + cin >> x; + } + sort(v.begin(), v.end()); + for(int i = 0; i < n - 1; i++){ + // 1 2 3 4 5 6 7 + res.push_back(abs(v[i] - v[i+1])); + } + cout << *min_element(res.begin(), res.end()) << endl; + return 0; +} + diff --git a/RecursiveDigitSum.py b/RecursiveDigitSum.py new file mode 100644 index 0000000..4d7dbd7 --- /dev/null +++ b/RecursiveDigitSum.py @@ -0,0 +1,14 @@ +x,n = map(int, input().split()) +x = str(x) +x = x * n +print(x) +def recursive_digit_sum(x): + y = 0 + if len(x) == 1: + return x; + else: + for i in x: + y += int(i) + print("y: ", y) + return recursive_digit_sum(str(y)) +print(recursive_digit_sum(x)) diff --git a/SequenceEquation.cpp b/SequenceEquation.cpp new file mode 100644 index 0000000..1714728 --- /dev/null +++ b/SequenceEquation.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +int main(){ + int n, count = 1; + cin >> n; + vector v(n); + map mp; + for(auto &x : v){ + cin >> x; + mp[x] = count; + count++; + } + for(auto x : mp){ + auto it = find(v.begin(), v.end(), x.second); + cout << "value: " << x.first << " Index: " << x.second << endl; + cout << it - v.begin() + 1<< endl; + } + + + + + return 0; +} diff --git a/ThePowerSum.cpp b/ThePowerSum.cpp new file mode 100644 index 0000000..7f7e032 --- /dev/null +++ b/ThePowerSum.cpp @@ -0,0 +1,36 @@ +#include + +using namespace std; + +int power(int base, int p){ + if(p == 0) { + return 1; + } + return base * (power(base, p - 1)); +} + +vector ans; + +int powerSum(int x, int n, int lastDigit) { + if (x == 0) { + for(int x : ans) { + cout << x << "^" << n << " + "; + } + cout << endl; + return 1; + } + int sum = 0; + for(int i = lastDigit; x - power(i, n) >= 0; i++) { + ans.push_back(i); + sum += powerSum(x - power(i, n), n, i + 1); + ans.pop_back(); + } + return sum; +} + +int main() { + int x, n, count = 0; + cin >> x >> n; + cout << powerSum(x, n, 1) << endl; + return 0; +} diff --git a/chocolateFeast.cpp b/chocolateFeast.cpp new file mode 100644 index 0000000..b7c6fcc --- /dev/null +++ b/chocolateFeast.cpp @@ -0,0 +1,43 @@ +#include +using namespace std; +int main(){ + int n, c, m, rem=0, wrap, result, tt, choc; + cin >> tt; + while(tt--){ + cin >> n >> c >> m; + rem = 0; + choc = n / c; + rem += n % c; + result = choc; + wrap = choc; + while(wrap >= m){ + wrap = wrap / m; + result += wrap; + rem += wrap % m; + } + rem += wrap % m; + result += rem / m; + cout << result << endl; + } +} + + + + + + + + + + + + + + + + + + + + + diff --git a/chocolateFeastRevised.cpp b/chocolateFeastRevised.cpp new file mode 100644 index 0000000..edaa983 --- /dev/null +++ b/chocolateFeastRevised.cpp @@ -0,0 +1,19 @@ +#include + +using namespace std; + +int main() { + int tt; + cin >> tt; + while (tt--) { + int n, c, m; + cin >> n >> c >> m; + long long ans = n / c, cur = ans; + while (cur >= m) { + ans += cur / m; + cur = (cur % m) + (cur / m); + } + cout << ans << '\n'; + } + return 0; +} diff --git a/cutTheSticks.cpp b/cutTheSticks.cpp new file mode 100644 index 0000000..5c2c700 --- /dev/null +++ b/cutTheSticks.cpp @@ -0,0 +1,63 @@ +#include + +using namespace std; + +bool vectorZero(vector& v); +int secondSmallest(vector& v); + +int main(){ + int vsize; + int count=0; + vector vec; + cin >> vsize; + vector result; + for(int i = 0; i < vsize; i++){ + int element; + cin >> element; + vec.push_back(element); + } + sort(vec.begin(), vec.end()); + int mn = *min_element(vec.begin(), vec.end()); + for(int i = 0; i < vsize; i++){ + if(vec[i] != 0){ + vec[i]-= mn; + } + } + cout << vsize; + while(!vectorZero(vec)){ + int ss = vec[secondSmallest(vec)]; + count = 0; + for(int x : vec){ + cout << x << " "; + } + cout << endl; + for(int i = 0; i < vsize; i++){ + if(vec[i] != 0){ + vec[i] -= ss; + count++; + } + } + cout << count << endl; + } + return 0; +} + + +bool vectorZero(vector& v){ + int count = 0; + for(int i = 0; i < v.size(); i++){ + if(v[i] == 0){ + count++; + } + } + return count == v.size(); +} + +int secondSmallest(vector& v){ + for(int i = 0; i < v.size(); i++){ + if(v[i] != *min_element(v.begin(), v.end())){ + return i; + } + } + return -1; +} diff --git a/cutTheSticksJoe.cpp b/cutTheSticksJoe.cpp new file mode 100644 index 0000000..4504062 --- /dev/null +++ b/cutTheSticksJoe.cpp @@ -0,0 +1,21 @@ +#include + +using namespace std; + +int main() { + ios::sync_with_stdio(false); + cin.tie(0); + int n; + cin >> n; + map mp; + for (int i = 0; i < n; i++) { + int x; + cin >> x; + ++mp[x]; + } + for (auto p : mp) { + cout << n << '\n'; + n -= p.second; + } + return 0; +} diff --git a/cutTheSticksRevised.cpp b/cutTheSticksRevised.cpp new file mode 100644 index 0000000..0d63fb4 --- /dev/null +++ b/cutTheSticksRevised.cpp @@ -0,0 +1,10 @@ +#include + +using namespace std; + +int main(){ + + + + return 0; +} diff --git a/iceCreamParlor.cpp b/iceCreamParlor.cpp new file mode 100644 index 0000000..eb29391 --- /dev/null +++ b/iceCreamParlor.cpp @@ -0,0 +1,38 @@ +#include + +using namespace std; + +bool cleanVec(vector v){ + sort(v.begin(), v.end()); + for(int i = 0; i < v.size() - 1; i++) { + if(v[i] == v[i + 1]) { + return true; + } + } + return false; +} + +int main() { + int t,m,n; + cin >> t; + while(t--) { + cin >> m; + cin >> n; + vector v(n); + for(int &x : v) { + cin >> x; + } + for(int i = 1; i <= n; i++) { + auto it = find(v.begin() + i, v.end(), m - v[i - 1]); + if(it != v.end() && cleanVec(v)) { + cout << v.end() - it - i - 1 << " " << it - v.begin() + i << '\n'; + break; + } + else { + cout << v.end() - it - i << " " << it - v.begin() + i << '\n'; + break; + } + } + } + return 0; +} diff --git a/python/FindDigits.py b/python/FindDigits.py new file mode 100755 index 0000000..6bdfebf --- /dev/null +++ b/python/FindDigits.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + + +def find_digit(n): + count = 0 + list = [int(i) for i in n] + for i in range(len(n)): + if list[i] == 0: + continue + if int(n) % list[i] == 0: + count = count + 1 + return count + +t = int(input()) + +while(t): + t = t - 1; + n = input() + print(find_digit(n)) + + diff --git a/python/Kaprekar.py b/python/Kaprekar.py new file mode 100755 index 0000000..199b1c2 --- /dev/null +++ b/python/Kaprekar.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +from math import ceil + +p = int(input()) +q = int(input()) + +def splitNum(n): + sn = str(n) + l = len(sn) + d = int((l + 1) / 2) + if l % 2 == 0: + d = int(ceil(l / 2)) + if(len(sn[d:].lstrip('0')) != 0): + return int(sn[0:l - d]) + int(sn[l-d:].lstrip('0')) + +for i in range(p, q): + if i == splitNum(i * i): + print(i) + + -- cgit v1.2.3