Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4. void Bitmask(char[], char[], int*,int);
  5. void Razlika(int*, int*,int);
  6. bool Equal(int*, int*, int);
  7. int main() {
  8. char set[] = "abcde";
  9.  
  10. int size = strlen(set);
  11. cout << "The size of the array is: " << size << endl;
  12. int* bitmask = new int[size];
  13. char set2[] = "bed";
  14.  
  15. Bitmask(set, set2, bitmask, size);
  16. cout << endl;
  17. int counter = 0;
  18. for (unsigned i = 0; i < size; i++)if (bitmask[i] == 1) counter++;
  19. cout << "The power of the set is: " << counter << endl;
  20.  
  21. //2 ZADACHA
  22. char setA[] = "bce";
  23. char setB[] = "bec";
  24. int* bitmaskA = new int[size];
  25. int* bitmaskB = new int[size];
  26. cout << "The bitmask of A is: ";
  27. Bitmask(set, setA, bitmaskA, size);
  28. cout << "\nThe bitmask of B is: ";
  29. Bitmask(set, setB, bitmaskB, size);
  30. cout << "\nThe result is: ";
  31. Razlika(bitmaskA, bitmaskB, size);
  32. cout << endl;
  33. //3 ZADACHA
  34. if (Equal(bitmaskA, bitmaskB, size)) cout << "Set A is equal to Set B" << endl;
  35. else cout << "Set A and Set B are not equal" << endl;
  36. //5 zadacha
  37.  
  38.  
  39. if (bitmask != nullptr) {
  40. delete[] bitmask;
  41. bitmask = nullptr;
  42. }
  43. if (bitmaskA != nullptr) {
  44. delete[] bitmaskA;
  45. bitmaskA = nullptr;
  46. }
  47. if (bitmaskB != nullptr) {
  48. delete[] bitmaskB;
  49. bitmaskB = nullptr;
  50. }
  51. return 0;
  52. }
  53. void Bitmask(char set[], char set2[], int* bitmask, int size) {
  54. for (unsigned i = 0; i < size; i++) bitmask[i] = 0;
  55. //cikul za set2
  56. for (unsigned i = 0; set2[i] != '\0'; i++)
  57. {
  58. //cikul za set1
  59. for (unsigned j = 0; set[j] != '\0'; j++)
  60. {
  61. if (set2[i] == set[j]) bitmask[j] = 1;
  62. }
  63. }
  64. //pechatane
  65. for (unsigned t = 0; t < size; t++) {
  66. cout << bitmask[t];
  67. }
  68. }
  69. void Razlika(int* bitmaskA, int* bitmaskB,int size) {
  70. int* Result = new int[size];
  71. for (unsigned j = 0; j < size; j++)Result[j] = 0;
  72. for (unsigned i = 0; i < size; i++)
  73. {
  74. if (bitmaskA[i] != bitmaskB[i] && bitmaskA[i]==1) Result[i] = 1;
  75. }
  76. for (unsigned t = 0; t < size; t++)cout << Result[t];
  77. if (Result != nullptr) {
  78. delete[] Result;
  79. Result = nullptr;
  80. }
  81. }
  82. bool Equal(int* bitmaskA, int* bitmaskB, int size) {
  83. //broqch za 1cite za da se proveri dali ima suvpadenie
  84. int counter = size, tmp = 0;
  85. for (unsigned j = 0; j < size; j++) {
  86. if (bitmaskA[j] == bitmaskB[j]) tmp++;
  87. if (counter == tmp) return true;
  88. }
  89.  
  90. return false;
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement