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

........ #21

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
142 changes: 121 additions & 21 deletions src/Task1/task1.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,126 @@
#include <bits/stdc++.h>
using namespace std;
using namespace std;
#include<bits/stdc++.h>
#include<sstream>
#include<vector>
#include<map>
#include<string>
#include<iostream>
using namespace std;
int answer=0;


int solve(int n, vector<string> arr){
int answer=0;
// Start your code here
int solve(int n, vector<string> arr){
int answer=0;
// Start your code here
map<string,int> 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<string> arr(n);
// for(int i=0;i<n;i++){
// getline(cin,arr[i]);
// cout<<arr[i]<<endl;
// }
// cout<<solve(n,arr);
return 0;
}
else if(command=="addi")
{
stringstream string_to_number(r);
int i=0;
string_to_number>>i;
map1[p]=map1[q]+i;
}


// ==> NOTE: Comment main function and uncomment below line to verify your code
// #include "../../include/test1_cases.h"
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<string> 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<n;j++)
{ string str=arr1[j];
stringstream sstr;
sstr<<str;
sstr>>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<string> arr(n);
// for(int i=0;i<n;i++){
// getline(cin,arr[i]);
// cout<<arr[i]<<endl;
// }
// cout<<solve(n,arr);
/*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;
}
}*/


// ==> NOTE: Comment main function and uncomment below line to verify your code
// #include "../../include/test1_cases.h"
#include "../../include/test1_cases.h"
202 changes: 157 additions & 45 deletions src/Task2/task2.cpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,158 @@
#include <bits/stdc++.h>
using namespace std;


class Solution {
private:
int n; // n is size that user inputs
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
}
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(){
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

return 0;
}

// ==> NOTE: Comment main function and uncomment below line to verify your code
// #include "../../include/test2_cases.h"
using namespace std;
class Solution {
private:
int n;
vector<unsigned int> v, ans1, ans2, ans3;
void solve_task1()
{
set<unsigned int> set1;
for (int i = 0; i < n; i++)
set1.insert(v[i]);
for (int i : set1)
ans1.push_back(i);
}
bool compare_pairs(pair<unsigned int, unsigned int> pairs1, pair<unsigned int, unsigned int> 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<pair<unsigned int,unsigned int>> sorttask2(vector<pair<unsigned int,unsigned int>> v, int n)
{
pair<unsigned int,unsigned int> 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<pair<unsigned int, unsigned int>> pairs3;
for (int i = 1; i <= n / 2; i++)
{
pair<unsigned int, unsigned int> 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<pair<unsigned int, unsigned int>> pairs5;
for (int i = 1; i <= n / 2; i++)
{
pair<unsigned int, unsigned int> p;
p.first = v[2 * i - 2];
p.second = v[2 * i - 1];
pairs5.push_back(p);
}


queue<unsigned int> q;
for (pair<unsigned int, unsigned int> 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<unsigned int> 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<unsigned int> 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<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",
// };
// return 0;
// }
// ==> NOTE: Comment main function and uncomment below line to verify your code
#include "../../include/test2_cases.h"