diff --git a/Algorithms/Bit Manipulation/Sum vs XOR.cpp b/Algorithms/Bit Manipulation/Sum vs XOR.cpp new file mode 100644 index 0000000..5d2f95f --- /dev/null +++ b/Algorithms/Bit Manipulation/Sum vs XOR.cpp @@ -0,0 +1,60 @@ +#include + +using namespace std; + +string ltrim(const string &); +string rtrim(const string &); + +// Complete the sumXor function below. +long sumXor(long n) { +int ctr=0; +while(n) +{ + if(n%2==0) + { + ctr++; + } + n/=2; +} + return pow(2,ctr); +} + +int main() +{ + ofstream fout(getenv("OUTPUT_PATH")); + + string n_temp; + getline(cin, n_temp); + + long n = stol(ltrim(rtrim(n_temp))); + + long result = sumXor(n); + + fout << result << "\n"; + + fout.close(); + + return 0; +} + +string ltrim(const string &str) { + string s(str); + + s.erase( + s.begin(), + find_if(s.begin(), s.end(), not1(ptr_fun(isspace))) + ); + + return s; +} + +string rtrim(const string &str) { + string s(str); + + s.erase( + find_if(s.rbegin(), s.rend(), not1(ptr_fun(isspace))).base(), + s.end() + ); + + return s; +} diff --git a/Algorithms/Implementation/Climbing_the_Leaderboard.cpp b/Algorithms/Implementation/Climbing_the_Leaderboard.cpp new file mode 100644 index 0000000..2f56b24 --- /dev/null +++ b/Algorithms/Implementation/Climbing_the_Leaderboard.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +std::vector vec; + +int main() +{ + int n, q, v; + std::cin >> n; + for (int i = 0; i < n; i++) + { + std::cin >> v; + vec.push_back(v); + } + std::sort(vec.begin(), vec.end()); + vec.resize(std::distance(vec.begin(), std::unique(vec.begin(), vec.end()))); + std::cin >> q; + while (q--) + { + std::cin >> v; + std::cout << std::distance(std::upper_bound(vec.begin(), vec.end(), v), vec.end())+1 << '\n'; + } +} diff --git a/Algorithms/Implementation/Encryption.cpp b/Algorithms/Implementation/Encryption.cpp new file mode 100644 index 0000000..e1484a6 --- /dev/null +++ b/Algorithms/Implementation/Encryption.cpp @@ -0,0 +1,31 @@ +#include + +using namespace std; + +// Complete the encryption function below. +void encryption(string s) { + int l=s.size(); + int row=round(sqrt(l)); + int column; + if(row>=sqrt(l)) + column=row; + else column=row+1; + for(int j=0;j