50057. Consecutive 0's and 1's

難度:3/5

找i-th bit的function是:

1
2
3
static inline int get_i_bit(int num, int i){
return (num >> i) & 1;
}

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
#include <stdio.h>
#include <stdlib.h>

static inline int get_i_bit(int num, int i){
return (num >> i) & 1;
}

int main(){
int n, cnt = 0, last = -1;
scanf("%d", &n);
while(n--){
int d; scanf("%d", &d);
for(int i = 31; i >= 0; i--){
int b = get_i_bit(d, i);
if(last != -1 && last != b){
printf("\n");
for(int j = 0; j < cnt % 40; j++) printf(" ");
}
printf("%d", b);
last = b, cnt++;
}
}
puts("");
}


50057. Consecutive 0's and 1's
https://aaronlin1229.github.io/judgegirl_50057/
Author
Akizumi
Posted on
July 17, 2023
Licensed under