diff --git a/src/Task1/task1.cpp b/src/Task1/task1.cpp index 9fb7ff4..9abd78f 100755 --- a/src/Task1/task1.cpp +++ b/src/Task1/task1.cpp @@ -1,26 +1,126 @@ #include -using namespace std; + using namespace std; + #include + #include + #include + #include + #include + #include + using namespace std; + int answer=0; + -int solve(int n, vector arr){ - int answer=0; - // Start your code here + int solve(int n, vector arr){ + int answer=0; + // Start your code here + map map1; + void calculation(string command,string p,string q,string r) + { + - // End your code here - return answer; -} + // End your code here + if(command=="add") + map1[p]=map1[q]+map1[r]; + else if(command=="sw") + map1["answer"]=map1[p]; + else if(command=="mul") + map1[p]=map1[q]*map1[r]; + else if(command=="sub") + map1[p]=map1[q]-map1[r]; + else if(command=="and") + map1[p] = map1[q] & map1[r]; + else if(command=="or") + map1[p] = map1[q] | map1[r]; + -int main(){ - // int n; - // cin>>n; - // cin.ignore(); - // vector arr(n); - // for(int i=0;i>i; + map1[p]=map1[q]+i; + } + -// ==> NOTE: Comment main function and uncomment below line to verify your code -// #include "../../include/test1_cases.h" \ No newline at end of file + else if(command=="li") + { + stringstream string_to_num(q); + int i=0; + string_to_num>>i; + map1[p]=i; + } + else if(command=="ori") + { + stringstream string_to_num(r); + int i=0; + string_to_num>>i; + map1[p]=map1[q]|i; + } + else if(command=="andi") + { + stringstream string_to_num(r); + int i=0; + string_to_num>>i; + map1[p] = map1[q] & i; + } + } + int solve(int n, vector arr1){ + for (int j = 0; j < n; j++) + { + string str1; + for (int k = 0; k < arr1[j].size(); k++) + { + if(arr1[j][k] !=',') + { + str1=str1+arr1[j][k]; + } + } + arr1[j]=str1; + } + for(int j=0;j>str; + string command=str; + sstr>>str; + string p=str; + sstr>>str; + string q=str; + sstr>>str; + string r=str; + calculation(command,p,q,r); + } + answer = map1["answer"]; + return answer; + } + + + int main(){ + // int n; + // cin>>n; + // cin.ignore(); + // vector arr(n); + // for(int i=0;i>n; + cin.ignore(); + vector arr(n); + for(int i=0;i NOTE: Comment main function and uncomment below line to verify your code + // #include "../../include/test1_cases.h" + #include "../../include/test1_cases.h" diff --git a/src/Task2/task2.cpp b/src/Task2/task2.cpp index e0056ee..43945f6 100755 --- a/src/Task2/task2.cpp +++ b/src/Task2/task2.cpp @@ -1,46 +1,158 @@ #include -using namespace std; - - -class Solution { - private: - int n; // n is size that user inputs - vectorv,ans1,ans2,ans3; // v is the vector that user inputs - void solve_task1(){ - // solve task1 and save the answer in ans1 - } - void solve_task2(){ - // solve task2 and save the answer in ans2 - } - void solve_task3(){ - // solve task3 and save the answer in ans3 - } - - public: - // create a constructor to take input - - string FINDMATCH(string path){ - // complete this function to read file, compare with ans1, ans2, ans3 - // and return the answer - } -}; - - - -int main(){ - vectora{5,7,6,5,2,1,4,0,1,3}; - string paths[]={ - "missing_files/missing1.bin", - "missing_files/missing2.bin", - "missing_files/missing3.bin", - "missing_files/missing4.bin", - }; - // Intialize your solution object here - - // Make a for loop to go through paths array and call FINDMATCH function - - return 0; -} - -// ==> NOTE: Comment main function and uncomment below line to verify your code -// #include "../../include/test2_cases.h" \ No newline at end of file + using namespace std; + class Solution { + private: + int n; + vector v, ans1, ans2, ans3; + void solve_task1() + { + set set1; + for (int i = 0; i < n; i++) + set1.insert(v[i]); + for (int i : set1) + ans1.push_back(i); + } + bool compare_pairs(pair pairs1, pair pairs2) + { + + + if (pairs1.second > pairs2.second) + return false; + else if (pairs1.second == pairs2.second) + { + if (pairs1.first > pairs2.first) + return true; + else + return false; + } + else + return true; + } + vector> sorttask2(vector> v, int n) + { + pair vtemp; + for (int i = 0; i < n; i++) + { + for (int j = i + 1; j < n; j++) + { + if (compare_pairs(v[i], v[j])) + { + vtemp = v[i]; + v[i] = v[j]; + v[j] = vtemp; + } + } + } + return v; + } + + + void solve_task2() + { + vector> pairs3; + for (int i = 1; i <= n / 2; i++) + { + pair pairs4; + pairs4.first = v[2 * i - 2]; + pairs4.second = v[2 * i - 1]; + pairs3.push_back(pairs4); + }e + pairs3 = sorttask2(pairs3, n / 2); + + + for (int i = 0; i < n / 2; i++) + ans2.push_back(pairs3[i].first); + } + void solve_task3() + { + vector> pairs5; + for (int i = 1; i <= n / 2; i++) + { + pair p; + p.first = v[2 * i - 2]; + p.second = v[2 * i - 1]; + pairs5.push_back(p); + } + + + queue q; + for (pair p : pairs5) + { + if (p.first % 2 == 1) + q.push(p.second); + else + { + q.push(p.second); + q.pop(); + } + } + + + int elmnt; + while (!q.empty()) + { + elmnt = q.front(); + ans3.push_back(elmnt); + q.pop(); + } + } + + + public: + Solution(int size, vector arr) + { + n = size; + v = arr; + solve_task1(); + solve_task2(); + solve_task3(); + } + string FINDMATCH(string path) + { + ifstream file; + file.open(path, ios::binary); + + + if (!file.is_open()){ + cout<<"The file can't be opened.\n"; + return "ERROR"; + } + + + file.seekg(0, ios::end); + int file_size = file.tellg(); + file.seekg(0, ios::beg); + + + unsigned int read_data; + int size_int = sizeof(int); + vector answer; + + + while(file.tellg() != file_size){ + file.read((char *) &read_data, size_int); + answer.push_back(read_data); + } + if (ans1==answer) return "TASK1"; + else if (ans2==answer) return "TASK2"; + else if (ans3==answer) return "TASK3"; + else return "NOTFOUND"; + + + } + }; + + + // int main() + // { + // vector a{5, 7, 6, 5, 2, 1, 4, 0, 1, 3}; + // string paths[] = { + // "missing_files/missing1.bin", + // "missing_files/missing2.bin", + // "missing_files/missing3.bin", + // "missing_files/missing4.bin", + // }; + // return 0; + // } + // ==> NOTE: Comment main function and uncomment below line to verify your code + #include "../../include/test2_cases.h"