Advertisement
wojiaocbj

E3-I

Mar 22nd, 2023
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <ctype.h>
  6. #include <time.h>
  7. #pragma warning(disable:4996 6031)
  8. int main(){
  9.     int op, group = 0, i, count;
  10.     char tmp[32] = { 0 };
  11.     while(~scanf("%d", &op)){
  12.         if(op == 0){
  13.             group++;
  14.             printf("Case %d:\n", group);
  15.             count = 0;
  16.             unsigned int s;
  17.             scanf("%u", &s);
  18.             char tmp[32] = { 0 };
  19.             for(i = 0; i < 26; i++){
  20.                 if(s & (1u << i)){
  21.                     tmp[count] = 'a' + i;
  22.                     count++;
  23.                 }
  24.             }
  25.             if(count){
  26.                 putchar('{');
  27.                 for(i = 0; i < count - 1; i++){
  28.                     putchar(tmp[i]);
  29.                     putchar(',');
  30.                 }
  31.                 putchar(tmp[count - 1]);
  32.                 putchar('}');
  33.                 putchar('\n');
  34.             }
  35.             else{
  36.                 puts("Empty set");
  37.             }
  38.         }
  39.         else if(op == 1){
  40.             group++;
  41.             printf("Case %d:\n", group);
  42.             int a, b, x;
  43.             char A[32] = { 0 }, B[32] = { 0 };
  44.             //hint
  45.             scanf("%d%d%d", &a, &b, &x);
  46.             while((A[0] = getchar()) < 'a' || A[0] > 'z');
  47.             for(i = 1; i < a; i++)
  48.                 A[i] = getchar();
  49.             while((B[0] = getchar()) < 'a' || B[0] > 'z');
  50.             for(i = 1; i < b; i++)
  51.                 B[i] = getchar();
  52.             //hint
  53.             //puts(A);
  54.             //puts(B);
  55.             unsigned int a0 = 0, b0 = 0;
  56.             for(i = 0; i < a; i++){
  57.                 a0 |= (1u << (A[i] - 'a'));
  58.             }
  59.             for(i = 0; i < b; i++){
  60.                 b0 |= (1u << (B[i] - 'a'));
  61.             }
  62.             if(a0 == b0){
  63.                 puts("Set A is equal to set B!");
  64.             }
  65.             else{
  66.                 if((a0 & b0) == a0){
  67.                     puts("Set A is the subset of set B!");
  68.                 }
  69.                 else if((a0 & b0) == b0){
  70.                     puts("Set B is the subset of set A!");
  71.                 }
  72.                 else{
  73.                     puts("No subset relationship!");
  74.                 }
  75.                 unsigned int result = 0;
  76.                 switch(x){
  77.                     case 1:
  78.                         result = a0 | b0;
  79.                         printf("The union of set A and set B is:");
  80.                         break;
  81.                     case 2:
  82.                         result = ~a0;
  83.                         printf("The complement of set A is:");
  84.                         break;
  85.                     case 3:
  86.                         result = a0 & (~b0);
  87.                         printf("The difference of set A and set B is:");
  88.                         break;
  89.                     case 4:
  90.                         result = ~(a0 & b0);
  91.                         printf("The complement of the intersection of set A and set B is:");
  92.                         break;
  93.                     case 5:
  94.                         result = ~(a0 | b0);
  95.                         printf("The complement of the union of set A and set B is:");
  96.                         break;
  97.                     default://0
  98.                         result = a0 & b0;
  99.                         printf("The intersection of set A and set B is:");
  100.                         break;
  101.                 }
  102.                 if(result & ((1u << 26) - 1)){
  103.                     putchar('{');
  104.                     count = 0;
  105.                     for(i = 0; i < 26; i++){
  106.                         if(result & (1u << i)){
  107.                             tmp[count] = 'a' + i;
  108.                             count++;
  109.                         }
  110.                     }
  111.                     for(i = 0; i < count - 1; i++){
  112.                         putchar(tmp[i]);
  113.                         putchar(',');
  114.                     }
  115.                     putchar(tmp[count - 1]);
  116.                     putchar('}');
  117.                     putchar('\n');
  118.                 }
  119.                 else{
  120.                     puts("Empty set");
  121.                 }
  122.             }
  123.         }
  124.     }
  125.     return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement