1.
#include <bits/stdc++.h>
using namespace std;
bool rightOrNot(char x);
set<string>Input();
void printSet(set<string> &SET);
set<string>U(set<string>&A,set<string>&B);
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
set<string> A =Input();
set<string> B =Input();
set<string> U_SET = U(A, B);
printSet(U_SET);
return 0;
}
bool rightOrNot(char x)
{
if (x >= '0' && x <= '9') return true;
if (x >= 'A' && x <= 'Z') return true;
if (x >= 'a' && x <= 'z') return true;
return false;
}
set<string>Input()
{
string m;
getline(cin, m);
int n = m.size();
set<string>allElements;
for (int i = 2; i < n; i++) {
if (rightOrNot(m[i])) {
string c;
while (rightOrNot(m[i])) {
c+=m[i];
i++;
}
allElements.insert(c);
}
}
return allElements;
}
set<string>U(set<string>&A,set<string>&B)
{
set<string>UnionSet;
for(auto &u:A)UnionSet.insert(u);
for(auto &u:B)UnionSet.insert(u);
return UnionSet;
}
void printSet(set<string> &SET)
{
cout << "Output=";
bool flag = true;
for (auto &v : SET) {
if(flag==true)cout<<v;
else
{
cout<<", "<<v;
flag=false;
}
cout<<"\n";
}
3.
#include <bits/stdc++.h>
using namespace std;
bool rightOrNot(char &x);
void print(vector<string> &A);
vector<string> Input();
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
vector<string> A = Input();
print(A);
return 0;
}
vector<string> Input()
{
string m;
getline(cin, m);
int n = m.size();
vector<string> allElements;
for (int i = 0; i < n; i++) {
if (rightOrNot(m[i])) {
string c;
while (rightOrNot(m[i])) {
c+= m[i];
i++;
}
allElements.push_back(c);
}
}
return allElements;
}
bool rightOrNot(char &x)
{
if (x >= '0' && x <= '9') return true;
if (x >= 'A' && x <= 'Z') return true;
if (x >= 'a' && x <= 'z') return true;
return false;
}
void print(vector<string> &A)
{
int n = A.size();
int totalSubSet = (1 << n);
cout << "Subset of A = ";
for (int i = 0; i < (1 << n); i++) {
cout << "{";
bool flag = true;
for (int j = 0; j < n; j++) {
int check = i & (1 << j);
if (check!=0) {
if(flag==true)cout<<A[j];
else
{
cout<<", "<<A[j];
}
flag = false;
}
}
if(i==totalSubSet-1)cout<<"}\n";
else cout<<"}, ";
}
cout << "|P(A)| = " << totalSubSet << endl;
}
5.
#include <iostream>
using namespace std;
struct Node {
int data;
Node* left;
Node* right;
Node(int val) : data(val), left(nullptr), right(nullptr) {}
};
Node* insert(Node* root, int data) {
if (!root) {
return new Node(data);
}
if (data < root->data) {
root->left = insert(root->left, data);
}
else if (data > root->data) {
root->right = insert(root->right, data);
}
return root;
}
int main() {
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
Node* root = nullptr;
int items[6];
for(int i=0;i<6;i++)cin>>items[i];
int n = sizeof(items) / sizeof(items[0]);
for (int i = 0; i < n; i++) {
root = insert(root, items[i]);
}
return 0;
}