HiLo


Submit solution

Points: 1 (partial)
Time limit: 1.0s
Memory limit: 67M

Author:
Problem type

Cho số tự nhiên n có thể biểu diễn dưới dạng nhị phân bởi không quá 16bit, hãy tìm 8 bit đầu và 8 bit cuối của n.

Đầu vào

Một số tự nhiên n duy nhất (0n2161).

Đầu ra

Dòng đầu tiên chứa 8 bit đầu tiên của n, dòng thứ hai chứa 8 bit cuối của n.

Ví dụ

Đầu vào:

Copy
1252

Đầu ra:

Copy
00000100
11100100
QDUY

Comments


  • 0
    Manh_KHMT_K64  commented 96 days ago
    Copy
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
     #include <math.h>
    char s[] = "0000000000000000";
    void bit(int n){
        while (n>0){
            int i = log2(n);
            s[16 - i -1 ] = '1';
            n -= pow(2,i);
        }
    }
    int main(){
        int n,i;
        scanf("%d", &n);
        bit(n);
        for (i = 0; i < 16; i++){
            printf("%c", s[i]);
            if (i == 7) printf("\n");
        }
    }
    

  • 3
    Lê_Thanh_Huyền_CNTT3_K63  commented on Sept. 30, 2024, 10:00 a.m.

    Code python 1 dòng cho mọi người tham khảo:

    Copy
    print("" if (r := f"{int(bin(int(input()))[2::]):016d}")==None else r[0:8]+"\n"+r[8:16])