Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <ctype.h>
- #include <time.h>
- #pragma warning(disable:4996 6031)
- int main(){
- int op, group = 0, i, count;
- char tmp[32] = { 0 };
- while(~scanf("%d", &op)){
- if(op == 0){
- group++;
- printf("Case %d:\n", group);
- count = 0;
- unsigned int s;
- scanf("%u", &s);
- char tmp[32] = { 0 };
- for(i = 0; i < 26; i++){
- if(s & (1u << i)){
- tmp[count] = 'a' + i;
- count++;
- }
- }
- if(count){
- putchar('{');
- for(i = 0; i < count - 1; i++){
- putchar(tmp[i]);
- putchar(',');
- }
- putchar(tmp[count - 1]);
- putchar('}');
- putchar('\n');
- }
- else{
- puts("Empty set");
- }
- }
- else if(op == 1){
- group++;
- printf("Case %d:\n", group);
- int a, b, x;
- char A[32] = { 0 }, B[32] = { 0 };
- //hint
- scanf("%d%d%d", &a, &b, &x);
- while((A[0] = getchar()) < 'a' || A[0] > 'z');
- for(i = 1; i < a; i++)
- A[i] = getchar();
- while((B[0] = getchar()) < 'a' || B[0] > 'z');
- for(i = 1; i < b; i++)
- B[i] = getchar();
- //hint
- //puts(A);
- //puts(B);
- unsigned int a0 = 0, b0 = 0;
- for(i = 0; i < a; i++){
- a0 |= (1u << (A[i] - 'a'));
- }
- for(i = 0; i < b; i++){
- b0 |= (1u << (B[i] - 'a'));
- }
- if(a0 == b0){
- puts("Set A is equal to set B!");
- }
- else{
- if((a0 & b0) == a0){
- puts("Set A is the subset of set B!");
- }
- else if((a0 & b0) == b0){
- puts("Set B is the subset of set A!");
- }
- else{
- puts("No subset relationship!");
- }
- unsigned int result = 0;
- switch(x){
- case 1:
- result = a0 | b0;
- printf("The union of set A and set B is:");
- break;
- case 2:
- result = ~a0;
- printf("The complement of set A is:");
- break;
- case 3:
- result = a0 & (~b0);
- printf("The difference of set A and set B is:");
- break;
- case 4:
- result = ~(a0 & b0);
- printf("The complement of the intersection of set A and set B is:");
- break;
- case 5:
- result = ~(a0 | b0);
- printf("The complement of the union of set A and set B is:");
- break;
- default://0
- result = a0 & b0;
- printf("The intersection of set A and set B is:");
- break;
- }
- if(result & ((1u << 26) - 1)){
- putchar('{');
- count = 0;
- for(i = 0; i < 26; i++){
- if(result & (1u << i)){
- tmp[count] = 'a' + i;
- count++;
- }
- }
- for(i = 0; i < count - 1; i++){
- putchar(tmp[i]);
- putchar(',');
- }
- putchar(tmp[count - 1]);
- putchar('}');
- putchar('\n');
- }
- else{
- puts("Empty set");
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement