当前位置:网站首页>3438. Number system conversion
3438. Number system conversion
2022-07-28 15:12:00 【Pursue people far away】
Find the conversion of any two non negative integers with different bases (2 Base number ∼ 16 Base number ), The integer given is in int Within the scope of .
The symbols of different bases are (0,1,…,9,a,b,…,f) perhaps (0,1,…,9,A,B,…,F)
Input format
There is only one line of input , Contains three integers a,n,b.a It means the following n yes a Hexadecimal integer ,b Express the desire to a Hexadecimal integer n convert to b Hexadecimal integer .
a,b It's a decimal integer .
Data may contain leading zeros .
Output format
The output contains a line , This line has an integer for the converted b Hexadecimal number .
When output, all alphabetic symbols are in upper case , namely (0,1,…,9,A,B,…,F).
Data range
2≤a,b≤16,
A given a Hexadecimal integer n The value range in decimal system is [1,2147483647].
sample input :
15 Aab3 7
sample output :
210306
Code :
#include <bits/stdc++.h>
using namespace std;
int ctoi(char c)
{
if (c <= '9')
return c - '0';
if (c <= 'Z')
return c - 'A' + 10;
return c - 'a' + 10;
}
char itoc(int x)
{
if (x < 10)
return '0' + x;
else
return 'A' + x - 10;
}
int main()
{
int a, b;
string num;
cin >> a >> num >> b;
int n = 0;
for (auto c: num)
n = n * a + ctoi(c);
string res;
while (n)
res += itoc(n % b), n /= b;
reverse(res.begin(),res.end());
cout << res << endl;
return 0;
}
边栏推荐
- 10、 C enum enumeration
- Matlab load usage
- Compose learning notes 1-compose, state, flow, remember
- 知识产权相关的风险评估要怎么做
- Knowledge map Foundation (I) - what is knowledge map
- Wonderful frog -- how simple can it be to abandon the float and use the navigation bar set by the elastic box
- What are the CCSP cloud security design principles
- JS常用的3种弹出框
- VTK annotation class widget vtkborderwidget
- 8、 C scope rules
猜你喜欢

Knowledge map Foundation (I) - what is knowledge map

Use of beefs

Compilation language and interpretation language

VTK vtkcontourwidget extracts regions of interest

Multi merchant mall system function disassembly lecture 17 - platform side order list

Instructions for common symbols in kotlin

9、 C array explanation

Creating, deleting and viewing Anaconda virtual environment

When MySQL uses left join to query tables, the query is slow because the connection conditions are not properly guided

The first self introduction quotation
随机推荐
UTF-8、UTF-16 和 UTF-32 字符编码之间的区别?[图文详解]
View gnuradio version
Mysql使用left join连表查询时,因连接条件未加索引导致查询很慢
Solution: attributeerror: type object 'h5py.h5a AttrID has no attribute __ reduce_ cython__
What are the main threats to cloud security
Multi merchant mall system function disassembly lecture 17 - platform side order list
Is the expansion operator a deep copy or a shallow copy
Talk about low code / zero code tools
JS learning notes 24-28: end
Mlx90640 infrared thermal imager sensor module development notes (VIII)
Mlx90640 infrared thermal imager sensor module development notes (VIII)
Application of edge technology and applet container in smart home
经典Dijkstra与最长路
RepVGG论文详解以及使用Pytorch进行模型复现
4、 C language operators
NCBI experience accumulation
手摸手实现Canal如何接入MySQL实现数据写操作监听
Image steganography method
PS modify the length and width pixels and file size of photos
22、 TF coordinate transformation (II): static coordinate transformation