Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main(){
- unsigned long long int bookshelf = 0;
- int a = 0;
- while(scanf("%d",&a) != EOF){
- int pos = -1;
- for(int i = 0; i < 8; i++){
- int k = ( bookshelf >> (i * 8) ) & (255);
- if (k == a){
- pos = i;
- }
- }
- /// 00000000 11111111 00000000 11111111 00000000 11111111 00000000 11111111
- /// -------- -------- -------- -------- -------- -------- -------- 11111111
- if(pos != -1){
- unsigned long long int newbookshelf = (bookshelf & ( (1ull << (pos * 8))-1 )) << 8;
- unsigned long long int q = (-1ull << (pos + 1) * 8);
- bookshelf = bookshelf & q;
- bookshelf = bookshelf | newbookshelf;
- }
- int empty = -1;
- for(int i = 7; i >= 0; i--){
- int s = ( bookshelf >> (i * 8) ) & (255);
- if(s == 0){
- empty = i;
- break;
- }
- }
- if(empty == -1){
- bookshelf <<= 8;
- empty = 0;
- }
- unsigned long long int emptybookshelf = (unsigned long long)a << (empty * 8);
- bookshelf = bookshelf | emptybookshelf;
- }
- for (int i = 7; i >= 0; i--){
- int w = ( bookshelf >> (i * 8) ) & (255);
- printf("%d ",w);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment