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

Create codingques.cpp #352

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
56 changes: 56 additions & 0 deletions codingques.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//Accenture Coding Test Questions and Answers
/*
Problem Description :
The Binary number system only uses two digits, 0 and 1 and number system can be called binary string. You are required to implement the following function:

int OperationsBinaryString(char* str);

The function accepts a string str as its argument. The string str consists of binary digits eparated with an alphabet as follows:

– A denotes AND operation
– B denotes OR operation
– C denotes XOR Operation
You are required to calculate the result of the string str, scanning the string to right taking one opearation at a time, and return the same.

Note:

No order of priorities of operations is required
Length of str is odd
If str is NULL or None (in case of Python), return -1
Input:
str: 1C0C1C1A0B1

Output:
1
*/
#include<bits/stdc++.h>
using namespace std;
int OperationsBinaryString (char *str)
{
if (str == NULL)
return -1;
int i = 1;
int a = *str - '0';
str++;
while (*str != '\0')
{
char p = *str;
str++;
if (p == 'A')
a &= (*str - '0');
else if (p == 'B')
a |= (*str - '0');
else
a ^= (*str - '0');
str++;
}
return a;
}
int main ()
{
string s;
getline (cin, s);
int len = s.size ();
char *str = &s[0];
cout << OperationsBinaryString (str);
}