码迷,mamicode.com
首页 > 其他好文 > 详细

P1017-进制转换

时间:2019-07-31 18:18:45      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:lse   put   main   type   str   line   last   name   names   

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 5 typedef long long ll;
 6 using namespace std;
 7 int m,n;
 8 inline ll read()
 9 {
10     ll ans = 0;
11     char ch = getchar(), last =  ;
12     while(!isdigit(ch)) last = ch, ch = getchar();
13     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - 0, ch = getchar();
14     if(last == -) ans = -ans;
15     return ans;
16 }
17 inline void write(ll x)
18 {
19     if(x < 0) x = -x, putchar(-);
20     if(x >= 10) write(x / 10);
21     putchar(x % 10 + 0);
22 }
23 char rnt[100];
24 int rntend = 0;
25 void f(int k,int r)
26 {
27     if(k==0) return ;
28     int le = k%r;
29     if(le<0) le-=r,k+=r;
30     f(k/r,r);
31     if(le>=10) rnt[rntend++] = A+le-10;
32     else rnt[rntend++] = le+0;
33 }
34 int main()
35 {
36     m = read(),n = read();f(m,n);
37     printf("%d=%s(base%d)\n",m,rnt,n);
38     return 0;
39 }

 

P1017-进制转换

标签:lse   put   main   type   str   line   last   name   names   

原文地址:https://www.cnblogs.com/Asurudo/p/11278025.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!