set
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | #include <stdio.h> #include <stdlib.h> #include <time.h> #define MAXIMUM 26 void Print_Union (char* Set_A, char* Set_B); void Print_Intersection (char* Set_A, char* Set_B); void Print_Difference_Of_Sets (char* Set_A, char* Set_B); void Insert_Random_Element (char* Element, int range); int main(int argc, char** argv) { char Set_A[MAXIMUM] = { 0, }; char Set_B[MAXIMUM] = { 0, }; srand((unsigned int) time (NULL)); Insert_Random_Element (Set_A, 10); printf ("Set A : %s\n", Set_A); Insert_Random_Element (Set_B, 15); printf ("Set B : %s\n", Set_B); printf ("\nUnion : "); Print_Union (Set_A, Set_B); printf ("\nIntersection : "); Print_Intersection (Set_A, Set_B); printf ("\nDifference of Sets : "); Print_Difference_Of_Sets (Set_A, Set_B); return 0; } void Insert_Random_Element (char* Element, int range) { if (range > 26) { printf ("Error! Out of range!\n"); return; } char Capital_Letter_Element_Count[26] = { 0, }; int index = 0; for (index = 0; index < range; index++) { int Random_Element = (rand() % 26) + 'A'; if (Capital_Letter_Element_Count[Random_Element - 'A']++ > 0) { index--; continue; } *(Element + index) = Random_Element; } *(Element + index) = 0; return; } void Print_Difference_Of_Sets (char* Set_A, char* Set_B) { char Capital_Letter_Element_Count[26] = { 0, }; while (*(Set_B)) Capital_Letter_Element_Count[*(Set_B++) - 'A']++; while (*(Set_A)) { if (Capital_Letter_Element_Count[*(Set_A) - 'A'] > 0) { *(Set_A++); continue; } printf ("[%c] ", *(Set_A)); Capital_Letter_Element_Count[*(Set_A++) - 'A']++; } return; } void Print_Intersection (char* Set_A, char* Set_B) { char Capital_Letter_Element_Count[26] = { 0, }; while (*(Set_A) + *(Set_B)) { if (Capital_Letter_Element_Count[*(Set_A) - 'A'] == 1) { printf ("[%c] ", *(Set_A++)); } else if (*(Set_A)) { Capital_Letter_Element_Count[*(Set_A++) - 'A']++; } if (Capital_Letter_Element_Count[*(Set_B) - 'A'] == 1) { printf ("[%c] ", *(Set_B++)); } else if (*(Set_B)) { Capital_Letter_Element_Count[*(Set_B++) - 'A']++; } } return; } void Print_Union (char* Set_A, char* Set_B) { char Capital_Letter_Element_Count[26] = { 0, }; while (*(Set_A) + *(Set_B)) { if (Capital_Letter_Element_Count[*(Set_A) - 'A'] > 0) { *(Set_A++); continue; } else if (*(Set_A)) { printf ("[%c] ", *(Set_A)); Capital_Letter_Element_Count[*(Set_A) - 'A']++; } if (Capital_Letter_Element_Count[*(Set_B) - 'A'] > 0) { *(Set_B++); continue; } else if (*(Set_B)) { printf ("[%c] ", *(Set_B)); Capital_Letter_Element_Count[*(Set_B) - 'A']++; } } return; } | cs |
0 개의 댓글:
댓글 쓰기