Advertisement
STANAANDREY

tpa t1pb1

Mar 3rd, 2023 (edited)
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #define NMAX 126
  4. #define SZUI8 (sizeof(uint8_t) * 8)
  5.  
  6. void setFlag(uint8_t *x, int pos) {
  7.   (*x) |= (1 << pos);
  8. }
  9.  
  10. int getFlag(uint8_t x, int pos) {
  11.   return 1 & (x >> pos);
  12. }
  13.  
  14. int main(void) {
  15.   int n;
  16.   scanf("%d", &n);
  17.   static uint8_t arr[NMAX];
  18.   for (int x, i = 0; i < n; i++) {
  19.     scanf("%d", &x);
  20.     setFlag(&arr[x / 8], x % SZUI8);
  21.   }
  22.  
  23.   for (int i = 0; i < NMAX; i++) {
  24.     for (int j = 0; j < SZUI8; j++) {
  25.       if (getFlag(arr[i], j)) {
  26.         printf("%d ", i * 8 + j);
  27.       }
  28.     }
  29.   }
  30.   puts("");
  31.   return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement