joylintp

222

Jan 12th, 2022
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. #include<stdio.h>
  2. int main(){
  3.     unsigned long long int bookshelf = 0;
  4.     int a = 0;
  5.     while(scanf("%d",&a) != EOF){
  6.         int pos = -1;
  7.         for(int i = 0; i < 8; i++){
  8.             int k = ( bookshelf >> (i * 8) ) & (255);
  9.             if (k == a){
  10.                 pos = i;
  11.             }  
  12.         }
  13.  
  14.     /// 00000000 11111111 00000000 11111111 00000000 11111111 00000000 11111111
  15.     /// -------- -------- -------- -------- -------- -------- -------- 11111111
  16.         if(pos != -1){
  17.             unsigned long long int newbookshelf = (bookshelf & ( (1ull << (pos * 8))-1 )) << 8;
  18.             unsigned long long int q = (-1ull << (pos + 1) * 8);
  19.             bookshelf = bookshelf & q;
  20.             bookshelf = bookshelf | newbookshelf;
  21.         }
  22.         int empty = -1;
  23.         for(int i = 7; i >= 0; i--){
  24.             int s = ( bookshelf >> (i * 8) ) & (255);
  25.             if(s == 0){
  26.                 empty = i;
  27.                 break;
  28.             }
  29.         }
  30.         if(empty == -1){
  31.             bookshelf <<= 8;
  32.             empty = 0;
  33.         }
  34.         unsigned long long int emptybookshelf = (unsigned long long)a << (empty * 8);
  35.         bookshelf = bookshelf | emptybookshelf;
  36.     }
  37.  
  38.     for (int i = 7; i >= 0; i--){
  39.         int w = ( bookshelf >> (i * 8) ) & (255);
  40.         printf("%d ",w);
  41.     }
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment