ACM模版
描述
题解
这个题让我很惆怅……给大家提供三种语言的代码,看看就知道了~~~
代码
One:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <cstring>
#include <algorithm>
#include <stdio.h>
#define ll unsigned long long
using namespace std;
const int MAXN = 100000 + 10;
const int MAXP_10 = 18;
const int MAXP_36 = 11;
const int MAGIC_1 = 4;
const int MAGIC_2 = 10;
const int MAGIC_3 = 13;
const int MAGIC_4 = 36;
int len_c;
ll r[MAXN * MAGIC_3];
ll c[MAXN];
ll pow_10[MAXP_10];
ll pow_36[MAXP_36];
char s[MAXN];
// 字符转换为数字
int cTon(char c)
{
if (c >= '0' && c <= '9')
{
return c - '0';
}
return c - 'A' + 10;
}
// 截位转换
void convert()
{
int t = 0;
int len = (int)strlen(s + 1);
for (int i = 1; i <= len; i++)
{
if ((i - 1) % MAGIC_1 == 0)
{
t++;
}
c[t] = c[t] * MAGIC_4 + cTon(s[i]);
}
len_c = t;
}
void solve()
{
ll num;
bool b;
for (int j = 1; j <= len_c; )
{
num = 0, b = false;
for (int i = j; i <= len_c; )
{
num = num * pow_36[MAGIC_1] + c[i];
c[i++] = 0;
if (num >= pow_10[MAGIC_3])
{
c[i - 1] = num / pow_10[MAGIC_3];
num %= pow_10[MAGIC_3];
}
if (c[i - 1])
{
b = 1;
}
if (!b)
{
j = i;
}
}
r[++r[0]] = num;
}
}
template <class T>
inline void print_d(T x)
{
if (x > 9)
{
print_d(x / 10);
}
putchar(x % 10 + '0');
}
void output()
{
print_d(r[r[0]]);
for (int i = (int)r[0] - 1; i > 0; i--)
{
ll x = r[i], t = 1;
while (x < pow_10[MAGIC_3 - t])
{
putchar('0');
t++;
}
print_d(r[i]);
}
putchar(10);
}
void init()
{
pow_10[0] = pow_36[0] = 1;
for (int i = 1; i < MAXP_10; i++)
{
pow_10[i] = pow_10[i - 1] * MAGIC_2;
}
for (int i = 1; i < MAXP_36; i++)
{
pow_36[i] = pow_36[i - 1] * MAGIC_4;
}
}
int main()
{
init();
scanf("%s", s + 1);
convert();
solve();
output();
return 0;
}
Two:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// go
//package main
//
//import
//(
// "bufio"
// "fmt"
// "math/big"
// "os"
//)
//
//func main()
//{
// bio := bufio.NewReader(os.Stdin)
// line, _ := bio.ReadString(0)
// n := big.NewInt(0)
// n.SetString(string(line), 36)
// fmt.Println(n.String())
//}
Three:
复制代码
1
2
// py3
//print(int(input(), 36))
最后
以上就是俭朴大雁最近收集整理的关于51Nod-1030-大数进制转换的全部内容,更多相关51Nod-1030-大数进制转换内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复