diff --git a/src/Task1/task1.cpp b/src/Task1/task1.cpp index 9fb7ff4..b81f20b 100755 --- a/src/Task1/task1.cpp +++ b/src/Task1/task1.cpp @@ -4,23 +4,181 @@ using namespace std; int solve(int n, vector arr){ int answer=0; // Start your code here + stringstream ss; + map mp1; + for(int i=0;i < n;i++) + { + stringstream ss; + ss<>s2; + if (s2.compare("li")==0){ + ss>>s2; + if(s2.find(',')!=string::npos) { + s2.erase(s2.find(','),1); + } + int x; + ss>>x; + mp1[s2]=x; + } + else if (s2.compare("add")==0) + { string s3,s4; + ss>>s2; + if(s2.find(',')!=string::npos) { + s2.erase(s2.find(','),1); + } + ss>>s3; + if(s3.find(',')!=string::npos) { + s3.erase(s3.find(','),1); + } + ss>>s4; + if(s4.find(',')!=string::npos) { + s4.erase(s4.find(','),1); + } + mp1[s2]=mp1[s3]+mp1[s4]; + } + else if (s2.compare("sub")==0){ + string s3,s4; + ss>>s2; + if(s2.find(',')!=string::npos) { + s2.erase(s2.find(','),1); + } + ss>>s3; + if(s3.find(',')!=string::npos) { + s3.erase(s3.find(','),1); + } + ss>>s4; + if(s4.find(',')!=string::npos) { + s4.erase(s4.find(','),1); + } + mp1[s2]=mp1[s3]-mp1[s4]; + } + else if (s2.compare("mul")==0){ + string s3,s4; + ss>>s2; + if(s2.find(',')!=string::npos) { + s2.erase(s2.find(','),1); + } + + ss>>s3; + if(s3.find(',')!=string::npos) { + s3.erase(s3.find(','),1); + } + + ss>>s4; + if(s4.find(',')!=string::npos) { + s4.erase(s4.find(','),1); + } + + mp1[s2]=mp1[s3]*mp1[s4]; + } + + + else if (s2.compare("and")==0){ + string s3,s4; + ss>>s2; + if(s2.find(',')!=string::npos) { + s2.erase(s2.find(','),1); + } + + ss>>s3; + if(s3.find(',')!=string::npos) { + s3.erase(s3.find(','),1); + } + + ss>>s4; + if(s4.find(',')!=string::npos) { + s4.erase(s4.find(','),1); + } + + mp1[s2]=mp1[s3]&mp1[s4]; + } + else if (s2.compare("or")==0){ + string s3,s4; + ss>>s2; + if(s2.find(',')!=string::npos) { + s2.erase(s2.find(','),1); + } + + ss>>s3; + if(s3.find(',')!=string::npos) { + s3.erase(s3.find(','),1); + } + + ss>>s4; + if(s4.find(',')!=string::npos) { + s4.erase(s4.find(','),1); + } + + mp1[s2]=mp1[s3]|mp1[s4]; + } + else if (s2.compare("andi")==0){ + string s3,s4; + ss>>s2; + if(s2.find(',')!=string::npos) { + s2.erase(s2.find(','),1); + } + + ss>>s3; + if(s3.find(',')!=string::npos) { + s3.erase(s3.find(','),1); + } + int x; + ss>>x; + mp1[s2]=mp1[s3]&x; + } + else if (s2.compare("ori")==0){ + string s3,s4; + ss>>s2; + if(s2.find(',')!=string::npos) { + s2.erase(s2.find(','),1); + } + + ss>>s3; + if(s3.find(',')!=string::npos) { + s3.erase(s3.find(','),1); + } + int x; + ss>>x; + mp1[s2]=mp1[s3]|x; + } + else if (s2.compare("addi")==0) + { string s3,s4; + ss>>s2; + if(s2.find(',')!=string::npos) { + s2.erase(s2.find(','),1); + } + ss>>s3; + if(s3.find(',')!=string::npos) { + s3.erase(s3.find(','),1); + } + int x; + ss>>x; + mp1[s2]=mp1[s3]+x; + } + else if (s2.compare("sw")==0){ + ss>>s2; + if(s2.find(',')!=string::npos) { + s2.erase(s2.find(','),1); + } + answer=mp1[s2]; + } + } // End your code here 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" \ No newline at end of file +#include "../../include/test1_cases.h" \ No newline at end of file diff --git a/src/Task2/task2.cpp b/src/Task2/task2.cpp index e0056ee..327ea27 100755 --- a/src/Task2/task2.cpp +++ b/src/Task2/task2.cpp @@ -8,39 +8,126 @@ class Solution { vectorv,ans1,ans2,ans3; // v is the vector that user inputs void solve_task1(){ // solve task1 and save the answer in ans1 + set st1; + for(int i=0;i:: iterator itr; + for(itr=st1.begin(); itr!=st1.end(); itr++){ + cout<< *itr<< ' '; + ans1.push_back(*itr); + } } void solve_task2(){ // solve task2 and save the answer in ans2 + vector> vec1; + vector vec2 = v; + for (auto itr=vec2.begin(); itr!=vec2.end(); itr+=2){ + vector temp={*itr,*(itr+1)}; + vec1.push_back(temp); + } + + vector temp1; + map> mp1; + for(auto itr=vec1.begin(); itr!=vec1.end();itr++){ + temp1.push_back((*itr)[1]); + mp1[(*itr)[1]]= *itr; + } + sort(temp1.begin(), temp1.end(), greater<>()); + for(auto itr=temp1.begin();itr!=temp1.end();itr++){ + ans2.push_back(mp1[*itr][0]); + } + } void solve_task3(){ // solve task3 and save the answer in ans3 + vector> vec1; + vector vec2 = v; + for (auto itr=vec2.begin(); itr!=vec2.end(); itr+=2){ + vector temp={*itr,*(itr+1)}; + vec1.push_back(temp); + } + + queue q1; + for(auto itr= vec1.begin(); itr!=vec1.end(); itr++){ + if((*itr)[0]%2!=0){ + q1.push((*itr)[1]); + } + else{ + q1.push((*itr)[1]); + q1.pop(); + } + } + queue q_temp=q1; + while(!q_temp.empty()){ + cout< v1){ + n=x; + v=v1; + solve_task1(); + solve_task2(); + solve_task3(); + + } + string FINDMATCH(string path){ // complete this function to read file, compare with ans1, ans2, ans3 + vector bfile; + ifstream binaryFile; + binaryFile.open(path, ios::in|ios::binary); + binaryFile.seekg(0,ios::end); + int length=binaryFile.tellg(); + binaryFile.seekg(0,ios::beg); + while(binaryFile.tellg()!=length){ + int x; + binaryFile.read((char*)&x, sizeof(int)); + bfile.push_back((int)x); + } + binaryFile.close(); + cout<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", - }; - // Intialize your solution object here +// 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 +// // Make a for loop to go through paths array and call FINDMATCH function - return 0; -} +// 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 + #include "../../include/test2_cases.h" \ No newline at end of file