Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- void Bitmask(char[], char[], int*,int);
- void Razlika(int*, int*,int);
- bool Equal(int*, int*, int);
- int main() {
- char set[] = "abcde";
- int size = strlen(set);
- cout << "The size of the array is: " << size << endl;
- int* bitmask = new int[size];
- char set2[] = "bed";
- Bitmask(set, set2, bitmask, size);
- cout << endl;
- int counter = 0;
- for (unsigned i = 0; i < size; i++)if (bitmask[i] == 1) counter++;
- cout << "The power of the set is: " << counter << endl;
- //2 ZADACHA
- char setA[] = "bce";
- char setB[] = "bec";
- int* bitmaskA = new int[size];
- int* bitmaskB = new int[size];
- cout << "The bitmask of A is: ";
- Bitmask(set, setA, bitmaskA, size);
- cout << "\nThe bitmask of B is: ";
- Bitmask(set, setB, bitmaskB, size);
- cout << "\nThe result is: ";
- Razlika(bitmaskA, bitmaskB, size);
- cout << endl;
- //3 ZADACHA
- if (Equal(bitmaskA, bitmaskB, size)) cout << "Set A is equal to Set B" << endl;
- else cout << "Set A and Set B are not equal" << endl;
- //5 zadacha
- if (bitmask != nullptr) {
- delete[] bitmask;
- bitmask = nullptr;
- }
- if (bitmaskA != nullptr) {
- delete[] bitmaskA;
- bitmaskA = nullptr;
- }
- if (bitmaskB != nullptr) {
- delete[] bitmaskB;
- bitmaskB = nullptr;
- }
- return 0;
- }
- void Bitmask(char set[], char set2[], int* bitmask, int size) {
- for (unsigned i = 0; i < size; i++) bitmask[i] = 0;
- //cikul za set2
- for (unsigned i = 0; set2[i] != '\0'; i++)
- {
- //cikul za set1
- for (unsigned j = 0; set[j] != '\0'; j++)
- {
- if (set2[i] == set[j]) bitmask[j] = 1;
- }
- }
- //pechatane
- for (unsigned t = 0; t < size; t++) {
- cout << bitmask[t];
- }
- }
- void Razlika(int* bitmaskA, int* bitmaskB,int size) {
- int* Result = new int[size];
- for (unsigned j = 0; j < size; j++)Result[j] = 0;
- for (unsigned i = 0; i < size; i++)
- {
- if (bitmaskA[i] != bitmaskB[i] && bitmaskA[i]==1) Result[i] = 1;
- }
- for (unsigned t = 0; t < size; t++)cout << Result[t];
- if (Result != nullptr) {
- delete[] Result;
- Result = nullptr;
- }
- }
- bool Equal(int* bitmaskA, int* bitmaskB, int size) {
- //broqch za 1cite za da se proveri dali ima suvpadenie
- int counter = size, tmp = 0;
- for (unsigned j = 0; j < size; j++) {
- if (bitmaskA[j] == bitmaskB[j]) tmp++;
- if (counter == tmp) return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement