-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoolean_String_Value (string).cpp
More file actions
62 lines (51 loc) · 1.05 KB
/
Copy pathBoolean_String_Value (string).cpp
File metadata and controls
62 lines (51 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
string BooleanString(string str1)
{
int i, n, x;
n = str1.size();
vector<string> arr(n);
for(i=0; i<n; i++)
arr[i].push_back(str1[i]);
i=0;
while(i < n-1)
{
if(arr[i] == "A")
{
x = stoi(arr[i-1]) * stoi(arr[i+1]);
arr[i+1] = to_string(x);
}
if(arr[i] == "B")
{
x = stoi(arr[i-1]) + stoi(arr[i+1]);
if(x == 2)
x = x-1;
arr[i+1] = to_string(x);
}
if(arr[i] == "C")
{
x = stoi(arr[i-1]) ^ stoi(arr[i+1]);
arr[i+1] = to_string(x);
}
i++;
}
return arr[n-1];
}
int main()
{
int t;
cout<<"\nEnter the Number of Testcases: ";
cin>>t;
while(t)
{
string str1, ans;
cout<<"\nEnter the String: ";
cin>>str1;
ans = BooleanString(str1);
cout<<"The Resultant String: "<<ans<<endl;
t--;
}
cout<<"\n";
return 0;
}