<cstdio>
,%i
可以自動判斷輸入的整數是 16 進位或 10 進位並存入 int
型別中,再自行判斷後用 %d
輸出 10 進位和 %X
輸出 16 進位(大寫字母)即可。<ios>
中有 std::showbase
、std::hex
、std::dec
、std::uppercase
等物件可以使用,如:
cout << hex << uppercase;
cout << "0x" << 44 << endl;
0x2C
cin
, cout
的同學,請在 main
函數一開始加上以下程式碼,避免超時。
ios_base::sync_with_stdio(false);
cin.tie(NULL);
0
或 0x0
的狀況。cin
、cout
時請注意速度。