575. 進制轉化
題目描述
給定一個十進制正整數,要求輸出這個正整數的二進制數、八進制數和十六進制數。
解答要求時間限制:1000ms, 內存限制:100MB
輸入
輸入數據只有一行,包含一個十進制正整數x(1 <= x <= 1000000000)
輸出
輸出一共3行,第一行輸出二進制數,第二行輸出八進制數,第三行輸出十六進制數,十六進制數中的字母采用大寫字母。
樣例
輸入樣例 1 復制
13
輸出樣例 1
1101 15 D
提示樣例 1
代碼:
// we have defined the necessary header files here for this problem. // If additional header files are needed in your program, please import here. void Trans_two(int N) { int a[1005],i = 0; while(N>0) { int t = N%2; N = N/2; a[i] = t; i++; } for (int k = i-1;k>=0;k--) cout<<a[k]; cout<<endl; } void Trans_eight(int N) { int a[1005],i = 0; while(N>0) { int t = N%8; N = N/8; a[i] = t; i++; } for (int k = i-1;k>=0;k--) cout<<a[k]; cout<<endl; } void Trans_sixteen(int N) { char arr []= "0123456789ABCDEF"; char hex[16]; int i = 0; while(N>0) { hex[i++] = arr[N%16]; N = N/16; } for (int k = i-1;k>=0;--k) cout<<hex[k]; cout<<endl; } int main() { // please define the C++ input here. For example: int a,b; cin>>a>>b;; // please finish the function body here. // please define the C++ output here. For example:cout<<____<<endl; int N; cin>>N; Trans_two(N); Trans_eight(N); Trans_sixteen(N); return 0; }
以大多數人努力程度之低,根本輪不到去拼天賦~

浙公網安備 33010602011771號