luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/HEX2BIN #864

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Chi tiết bài tập - Luyện Code Online

https://oj.luyencode.net/problem/HEX2BIN

luuquyhop commented 1 year ago

'///'

luuquyhop commented 1 year ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.

Xem code AC

```py def convert(n): if n == 0: return '' if n % 2 == 0: return convert(n // 2) + '0' else: return convert(n // 2) + '1' t = int(input()) for i in range(t): n = int(input(), 16) print(convert(n)) ```

btLong402 commented 1 year ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.

Xem code AC

```cpp #include using namespace std; unordered_map S; void init(){ S['0'] = "0000", S['1'] ="0001", S['2'] = "0010", S['3'] = "0011", S['4'] ="0100", S['5'] = "0101", S['6'] = "0110", S['7'] = "0111", S['8'] = "1000", S['9'] = "1001", S['A'] ="1010", S['B'] ="1011", S['C'] = "1100", S['D'] = "1101", S['E'] ="1110", S['F'] = "1111"; } void convertBIN(string a){ int len = a.length(); string res =""; for(int i = 0; i< len; i++){ for(int j = 0; j < 4; j++){ res.push_back(S[a[i]][j]); } } reverse(res.begin(), res.end()); while(res[res.length() - 1] == '0') res.pop_back(); reverse(res.begin(), res.end()); cout << res << endl; } int main(){ init(); int T; string a; cin >> T; while(T--){ cin >> a; convertBIN(a); } return 0; } ```