NOJ 1012 進位轉換(十進位轉換成任意進位),noj1012

來源:互聯網
上載者:User

NOJ 1012 進位轉換(十進位轉換成任意進位),noj1012

題目:

進位轉換時間限制(普通/Java) : 1000 MS/ 3000 MS          運行記憶體限制 : 65536 KByte
總提交 : 1819            測試通過 : 525 

題目描述

將一個十進位數N轉換成R進位數輸出,2≤R≤16,R≠10。



輸入

多行。第一行指出以下一共有多少組資料,後續每行包含兩個整數N和R,以空格分隔,-100000≤N≤100000,2≤R≤16,R≠10。

輸出

多行。每行給出轉換後的R進位數。

範例輸入

3
7 2
23 12
-4 3

範例輸出

111
1B
-11

提示

 

題目來源

GUOJ



題目分析:

             簡單題。利用itoa將十進位轉換成任意進位。。



代碼如下:

/* * a.cpp * *  Created on: 2015年3月31日 *      Author: Administrator */#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;const int maxn = 32;char numbers[maxn];void toUpper(char str[]){int i = 0;while(str[i] != '\0'){if(str[i] >= 'a' && str[i] <= 'z'){str[i] -= 32;}i++;}}int main(){int t;scanf("%d",&t);while(t--){int n;int base;scanf("%d%d",&n,&base);bool flag = false;if(n < 0){n = -n;flag = true;}itoa(n,numbers,base);toUpper(numbers);if(flag == true){printf("-");}printf("%s\n",numbers);}return 0;}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.