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

Task1 #12

Open
wants to merge 2 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
4 changes: 2 additions & 2 deletions include/doctest.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
DOCTEST_CLANG_SUPPRESS_WARNING("-Wunused-local-typedef") \
DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat") \
DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") \
\
\
DOCTEST_GCC_SUPPRESS_WARNING_PUSH \
DOCTEST_GCC_SUPPRESS_WARNING("-Wunknown-pragmas") \
DOCTEST_GCC_SUPPRESS_WARNING("-Wpragmas") \
Expand All @@ -167,7 +167,7 @@
DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs") \
DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast") \
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept") \
\
\
DOCTEST_MSVC_SUPPRESS_WARNING_PUSH \
/* these 4 also disabled globally via cmake: */ \
DOCTEST_MSVC_SUPPRESS_WARNING(4514) /* unreferenced inline function has been removed */ \
Expand Down
121 changes: 102 additions & 19 deletions src/Task1/task1.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,109 @@
#include <bits/stdc++.h>
using namespace std;

int solve(int n, vector<string> arr){
int answer=0;
// Start your code here
int solve(int n, vector<string> arr)
{
int answer = 0;
string temp, a, b, c;
// Started my code here
map<string, int> mp;
for (int i = 0; i < n; i++)
{
string s;
for (int j = 0; j < arr[i].size(); j++)
{
if (arr[i][j] != ',')
{
s += arr[i][j];
}
}
arr[i] = s;
}
for (int i = 0; i < n; i++)
{
string s = arr[i];
stringstream ss;
ss << s;
ss >> s;
temp = s;
ss >> s;
a = s;
ss >> s;
b = s;
ss >> s;
c = s;

// End your code here
if (temp == "li")
{
stringstream str_to_num(b);
int add = 0;
str_to_num >> add;
mp[a] = add;
}
else if (temp == "add")
{
mp[a] = mp[b] + mp[c];
}
else if (temp == "sub")
{
mp[a] = mp[b] - mp[c];
}
else if (temp == "addi")
{
stringstream str_to_num(c);
int add = 0;
str_to_num >> add;
mp[a] = mp[b] + add;
}
else if (temp == "mul")
{
mp[a] = mp[b] * mp[c];
}
else if (temp == "and")
{
mp[a] = mp[b] & mp[c];
}
else if (temp == "or")
{
mp[a] = mp[b] | mp[c];
}
else if (temp == "andi")
{
stringstream str_to_num(c);
int add = 0;
str_to_num >> add;
mp[a] = mp[b] & add;
}
else if (temp == "ori")
{
stringstream str_to_num(c);
int add = 0;
str_to_num >> add;
mp[a] = mp[b] | add;
}
else if (temp == "sw")
{
mp["answer"] = mp[a];
answer = mp["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);
return 0;
}
// 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"
// ==> NOTE: Comment main function and uncomment below line to verify your code
#include "../../include/test1_cases.h"
Binary file added src/Task1/task1.exe
Binary file not shown.