-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacsl.java
More file actions
54 lines (49 loc) · 1.04 KB
/
Copy pathacsl.java
File metadata and controls
54 lines (49 loc) · 1.04 KB
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
import java.lang.*;
import java.util.*;
public class acsl {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
for(int m = 0;m<5;m++){
int n = in.nextInt();
System.out.println(n);
int p = in.nextInt();
int act = n;
for (int i = 1; i<p;i++){
act = act / 10;
}
int pnum = act % 10 ;
int result = 0;
int j = 0;
int digit;
int scale;
while(n != 0){
if(j< p){
digit = Math.abs(n %10 - pnum);
scale = 1;
for(int i = 0; i<j; i++){
scale = scale * 10;
}
result = result + digit*scale;
}
if(j == p){
scale = 1;
for(int i = 0; i<j; i++){
scale = scale * 10;
}
result = result + pnum*scale;
}
if(j> p){
digit = (n %10 + pnum) % 10;
scale = 1;
for(int i = 0; i<j; i++){
scale = scale * 10;
}
result = result + digit*scale;
}
n = n / 10;
j++;
}
System.out.println(result);
}
}
}