标签:style blog http io ar color os sp for
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() { 14 printf("input element: "); 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(); 45 B.inp(); 46 C.intersectionSet(A, B); 47 D.unionSet(A, B); 48 A.outp("A: "); 49 B.outp("B: "); 50 C.outp("A ^ B: "); 51 D.outp("A v B: "); 52 } 53 return 0; 54 }
标签:style blog http io ar color os sp for
原文地址:http://www.cnblogs.com/jklongint/p/4120273.html