-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathDashInsert.java
More file actions
33 lines (23 loc) · 834 Bytes
/
Copy pathDashInsert.java
File metadata and controls
33 lines (23 loc) · 834 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
25
26
27
28
29
30
31
32
33
import java.util.*;
import java.io.*;
class Main {
public static String DashInsert(String str) {
char[] sayilar = str.toCharArray();
int oncekiSayi = Integer.parseInt(String.valueOf(sayilar[0]));
StringBuilder res = new StringBuilder(String.valueOf(oncekiSayi));
for (int i = 1; i < sayilar.length; i++) {
int sayi = Integer.parseInt(String.valueOf(sayilar[i]));
if (sayi != 0 && oncekiSayi % 2 == 1 && sayi % 2 == 1) {
res.append("-");
}
res.append(sayi);
oncekiSayi = sayi;
}
return res.toString();
}
public static void main(String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
System.out.print(DashInsert(s.nextLine()));
}
}