zoukankan      html  css  js  c++  java
  • [数据结构实验]集合交并

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 struct Set {
     6     bool mark[128];
     7     Set() {
     8         memset(mark, 0, sizeof(mark));
     9     }
    10     bool &operator [] (int x) {
    11         return mark[x];
    12     }
    13     void inp(char ss[]) {
    14         cout<< ss;
    15         char str[102];
    16         cin>> str;
    17         for(int i = 0; str[i]; i++) {
    18             if(str[i] == '$') break;
    19             mark[str[i]] = 1;
    20         }
    21     }
    22     void outp(char str[]) {
    23         cout<< str;
    24         for(char i = 0; i < 128 && i >= 0; i++) {
    25             if(mark[i]) cout<< i<< " ";
    26         }
    27         cout<< endl;
    28     }
    29     void intersectionSet(Set A, Set B) {
    30         for(int i = 0; i < 128; i++) {
    31             (*this)[i] = A[i] && B[i];
    32         }
    33     }
    34     void unionSet(Set A, Set B) {
    35         for(int i = 0; i < 128; i++) {
    36             (*this)[i] = A[i] || B[i];
    37         }
    38     }
    39 };
    40 int main()
    41 {
    42     while(1) {
    43         Set A, B, C, D;
    44         A.inp("A: ");
    45         B.inp("B: ");
    46         C.intersectionSet(A, B);
    47         D.unionSet(A, B);
    48         C.outp("A ^ B: ");
    49         D.outp("A v B: ");
    50     }
    51     return 0;
    52 }
    View Code
  • 相关阅读:
    20170728xlVba SSC_TODAY
    卸载angular版本
    union 共用体
    bootstrap的粗认识
    结构体,结构体数组,结构体指针
    C语言的枚举
    nodeJS 的认识
    nodejs 平台搭建
    动态表单
    指针
  • 原文地址:https://www.cnblogs.com/jklongint/p/4120273.html
Copyright © 2011-2022 走看看