-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp2745.java
More file actions
24 lines (22 loc) · 721 Bytes
/
p2745.java
File metadata and controls
24 lines (22 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.io.*;
import java.util.*;
public class p2745 {
static String n;
static int b;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = st.nextToken();
b = Integer.parseInt(st.nextToken());
int ans = 0;
for (int i = 0; i < n.length(); i++) {
char c = n.charAt(i);
if ('A' <= c && c <= 'Z') {
ans = ans * b + ((c - 'A') + 10);
} else {
ans = ans * b + (c - '0');
}
}
System.out.println(ans);
}
}