Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiverse of CPP Submission - Akshat Goel #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 173 additions & 15 deletions src/Task1/task1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,181 @@ using namespace std;
int solve(int n, vector<string> arr){
int answer=0;
// Start your code here
stringstream ss;
map<string, int> mp1;
for(int i=0;i < n;i++)
{
stringstream ss;
ss<<arr[i];
string s2;
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<string> arr(n);
// for(int i=0;i<n;i++){
// getline(cin,arr[i]);
// cout<<arr[i]<<endl;
// }
// cout<<solve(n,arr);
return 0;
}

// int main(){
// int n;
// cout<<"Enter the value of n";
// cin>>n;
// cin.ignore();
// vector<string> arr(n);
// for(int i=0;i<n;i++){
// getline(cin,arr[i]);
// cout<<arr[i]<<endl;
// }
// // return 0;
// }
// ==> NOTE: Comment main function and uncomment below line to verify your code
// #include "../../include/test1_cases.h"
#include "../../include/test1_cases.h"
113 changes: 100 additions & 13 deletions src/Task2/task2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,126 @@ class Solution {
vector<unsigned int>v,ans1,ans2,ans3; // v is the vector that user inputs
void solve_task1(){
// solve task1 and save the answer in ans1
set<int> st1;
for(int i=0;i<n;i++)
{
st1.insert(v[i]);
}
set<int>:: 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<vector <unsigned int>> vec1;
vector<unsigned int> vec2 = v;
for (auto itr=vec2.begin(); itr!=vec2.end(); itr+=2){
vector<unsigned int> temp={*itr,*(itr+1)};
vec1.push_back(temp);
}

vector<unsigned int> temp1;
map<int, vector<unsigned int>> 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<vector <unsigned int>> vec1;
vector<unsigned int> vec2 = v;
for (auto itr=vec2.begin(); itr!=vec2.end(); itr+=2){
vector<unsigned int> temp={*itr,*(itr+1)};
vec1.push_back(temp);
}

queue<int> 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<int> q_temp=q1;
while(!q_temp.empty()){
cout<<q_temp.front()<<" ";
q_temp.pop();
}

}

public:
// create a constructor to take input
Solution(int x, vector<unsigned int> 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<unsigned int> 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<<endl;
string str;
if(ans1==v){
str="TASK1";
}
else if(ans2==v){
str="TASK2";
}
else if(ans3==v){
str="TASK3";
}
else{
str="NOTFOUND";
}
return str;
// and return the answer
}
};



int main(){
vector<unsigned int>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(){
// vector<unsigned int>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

// 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"
#include "../../include/test2_cases.h"