diff --git a/ICPC Preparation/Data Structure/Bit Manipulation/11933_Splitting_Numbers.cpp b/ICPC Preparation/Data Structure/Bit Manipulation/11933_Splitting_Numbers.cpp new file mode 100644 index 0000000..9eb925d --- /dev/null +++ b/ICPC Preparation/Data Structure/Bit Manipulation/11933_Splitting_Numbers.cpp @@ -0,0 +1,64 @@ +#include +using namespace std; + +#define Fast ios::sync_with_stdio(0); cin.tie(0); + + +typedef long long ll; +typedef long int li; +typedef vector vi; +typedef vector vl; + +#define isOn(S, j) (S & (1< st; + while (vS) + st.push(vS%2), vS /= 2; + while (!st.empty()) // to reverse the print order + printf("%d", st.top()), st.pop(); + printf("\n"); +} + +int main(){ + Fast + while (true){ + int n;cin>>n; + if(n==0){ + break; + } + bool addToA = true; + int toAdd = 1; + int a = 0, b = 0; + while (n) { + if (isOn(n,0)){ + if (addToA) + a += toAdd; + else + b += toAdd; + + addToA = !addToA; + } + + toAdd *= 2; + n /= 2; + } + cout< +using namespace std; + +#define Fast ios::sync_with_stdio(0); cin.tie(0); + + +typedef long long ll; +typedef long int li; +typedef vector vi; +typedef vector vl; + +#define isOn(S, j) (S & (1< positios) { // in binary representation + for(int i = vS.size()-1; i>=0;i--){ + if(vS[i]!=-1){ + cout<>n; + if(n==0)break; + vi arr(32,-1); + set positios; + for (size_t i = 0; i < n; i++){ + string action;cin>>action; + int data=0, dataAc = 0; + if(action == "SET"){ + cin>>data; + arr[data]=1; + positios.insert(data); + } + if(action=="CLEAR"){ + cin>>data; + arr[data]=0; + positios.insert(data); + + } + if(action=="OR"){ + cin>>data; + cin>>dataAc; + if(arr[data]==1 || arr[dataAc]==1){ + arr[data]=1; + } + else if(arr[data]==0 && arr[dataAc]==0){ + arr[data]=0; + }else{ + arr[data]=-1; + } + } + if(action=="AND"){ + cin>>data; + cin>>dataAc; + if(arr[data]==1 && arr[dataAc]==1){ + arr[data]=1; + } + else if(arr[data]==0 && arr[dataAc]==0){ + arr[data]=0; + }else{ + arr[data]=-1; + } + } + } + printSet(arr, positios); + } + +} \ No newline at end of file diff --git a/ICPC Preparation/Data Structure/Bit Manipulation/bits.cpp b/ICPC Preparation/Data Structure/Bit Manipulation/bits.cpp new file mode 100644 index 0000000..d2fcb3c --- /dev/null +++ b/ICPC Preparation/Data Structure/Bit Manipulation/bits.cpp @@ -0,0 +1,44 @@ +#include +using namespace std; + +#define Fast ios::sync_with_stdio(0); cin.tie(0); + + +typedef long long ll; +typedef long int li; +typedef vector vi; +typedef vector vl; +#define isOn(S, j) (S & (1< st; + while (vS) + st.push(vS%2), vS /= 2; + while (!st.empty()) // to reverse the print order + printf("%d", st.top()), st.pop(); + printf("\n"); +} +int main(){ + Fast + int t;cin>>t; + while (t--) + { + ll n;cin>>n; + cout<<__builtin_popcount(n)< +using namespace std; + +#define Fast ios::sync_with_stdio(0); cin.tie(0); + + +typedef long long ll; +typedef long int li; +typedef vector vi; +typedef vector vl; +void insertionSort(vi arr, int n, int test) +{ + int aws = 0; + while (!is_sorted(arr.begin(), arr.end())){ + for (size_t i = 0; i < n-1; i++) + { + if(arr[i] > arr[i+1]) { + swap(arr[i], arr[i+1]); + aws++; + } + } + } + cout<>t; + int test = 0; + while (t--) + { + test++; + vi arr(20); + int n; cin>>n; + for (size_t i = 0; i < 20; i++) + { + cin>>arr[i]; + } + insertionSort(arr, 20, test); + + } + +} diff --git a/ICPC Preparation/Data Structure/Sorting/mjehuric.cpp b/ICPC Preparation/Data Structure/Sorting/mjehuric.cpp new file mode 100644 index 0000000..46fdd36 --- /dev/null +++ b/ICPC Preparation/Data Structure/Sorting/mjehuric.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; + +#define Fast ios::sync_with_stdio(0); cin.tie(0); + + +typedef long long ll; +typedef long int li; +typedef vector vi; +typedef vector vl; + +void printVector(vi arr){ + for (size_t i = 0; i < arr.size(); i++) + { + cout<>arr[i]; + } + while (!is_sorted(arr.begin(), arr.end())){ + if(arr[0] > arr[1]) { + swap(arr[0], arr[1]); + printVector(arr); + } + if(arr[1] > arr[2]) { + swap(arr[1], arr[2]); + printVector(arr); + } + if(arr[2] > arr[3]) { + swap(arr[2], arr[3]); + printVector(arr); + } + if(arr[3] > arr[4]) { + swap(arr[3], arr[4]); + printVector(arr); + } + } +} \ No newline at end of file diff --git a/ICPC Preparation/Data Structure/Sorting/sidewayssorting.cpp b/ICPC Preparation/Data Structure/Sorting/sidewayssorting.cpp new file mode 100644 index 0000000..e646036 --- /dev/null +++ b/ICPC Preparation/Data Structure/Sorting/sidewayssorting.cpp @@ -0,0 +1,30 @@ +#include +using namespace std; + +#define Fast ios::sync_with_stdio(0); cin.tie(0); + + +typedef long long ll; +typedef long int li; +typedef vector vi; +typedef vector vl; + +int main(){ + Fast + while (true){ + int n; cin>>n; + int r; cin>>r; + if(!r && !n){ + break; + } + for (size_t i = 0; i < n; i++) { + string s; cin>>s; + sort(s.begin(), s.end(),[](const char a, const char b){ + return toupper(a) +using namespace std; + +#define Fast ios::sync_with_stdio(0); cin.tie(0); + + +typedef long long ll; +typedef long int li; +typedef vector vi; +typedef vector vl; +typedef vector vs; + +void insertionSort(vs arr, int n) +{ + int aws = 0; + while (!is_sorted(arr.begin(), arr.end())){ + for (size_t i = 0; i < n-1; i++) + { + if(arr[i] > arr[i+1]) { + swap(arr[i], arr[i+1]); + } + } + } + for (size_t i = 0; i < n; i++) + { + arr[i][0]=toupper(arr[i][0]); + cout<>n; + vs arr(n); + if(!n){ + break; + } + for (size_t i = 0; i < n; i++) + { + cin>>arr[i]; + transform(arr[i].begin(), arr[i].end(), arr[i].begin(), [](unsigned char c){ return tolower(c); }); + } + insertionSort(arr, n); + + } + +} \ No newline at end of file diff --git a/ICPC Preparation/Data Structure/Stack/1062_Containers.cpp b/ICPC Preparation/Data Structure/Stack/1062_Containers.cpp new file mode 100644 index 0000000..c46f0a4 --- /dev/null +++ b/ICPC Preparation/Data Structure/Stack/1062_Containers.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; +int solve(string& s) { + vector >vs; + for (int i = 0;i < s.size();i++) { + if (vs.empty()) { + stackst; + vs.push_back(st); + vs[0].push(s[i]); + continue; + } + bool flag = false; + int mini = -1; + for (int j = 0;j < vs.size();j++) { + if (s[i] <= vs[j].top()) { + flag = true; + if (mini == -1) + mini = j; + else if (vs[mini].top() > vs[j].top()) { + mini = j; + } + } + } + if (!flag) + { + stackst; + vs.push_back(st); + vs[vs.size() - 1].push(s[i]); + } + else { + vs[mini].push(s[i]); + } + } + return vs.size(); +} +int main() +{ + string s; + cin >> s; + int i = 1; + while (s != "end") { + cout << "Case " << i++ << ": " << solve(s) << endl; + cin >> s; + } +} \ No newline at end of file diff --git a/ICPC Preparation/Data Structure/Stack/evenup.cpp b/ICPC Preparation/Data Structure/Stack/evenup.cpp new file mode 100644 index 0000000..48b80e2 --- /dev/null +++ b/ICPC Preparation/Data Structure/Stack/evenup.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; + +#define Fast ios::sync_with_stdio(0); cin.tie(0); + + +typedef long long ll; +typedef long int li; +typedef vector vi; +typedef vector vl; + +int main(){ + Fast + int n;cin>>n; + int num; + stack s; + cin >> num; + s.push(num); + for(int i=1;i> num; + if(!s.empty() && (num + s.top())%2 == 0) { + s.pop(); + } + else { + s.push(num); + } + } + cout << s.size() << endl; + + return 0; +} \ No newline at end of file