-
Notifications
You must be signed in to change notification settings - Fork 0
/
445.java
111 lines (96 loc) · 2.23 KB
/
445.java
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
/**
*
*/
package apr;
import java.io.*;
import java.lang.*;
import java.util.*;
/**
* @author Saif_sust_2013331007
*
*/
public class Main {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
try {
uva.Solver.Solution();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
class uva {
protected static class Solver {
private static String str;
protected static void Solution() {
int count = 0;
while (scanner.hasNext()) {
str = scanner.nextLine();
if (str.length()==0) {
System.out.println();
continue;
}
int arr[];
for (int i = 0; i < str.length(); i++) {
if (Character.isDigit(str.charAt(i))) {
arr = findNumber(str, i);
if (arr[0] == -1)
continue;
i = arr[1];
for (int j = 1; j <= arr[0]; j++) {
if (str.charAt(arr[1]) == 'b') {
System.out.print(" ");
} else {
if (str.charAt(arr[1]) == '!') {
System.out.println();
} else {
if (Character.isAlphabetic(str.charAt(arr[1])) || str.charAt(arr[1]) == '*') {
System.out.print(str.charAt(arr[1]));
} else {
int k = 0;
for (k = arr[1]; k < str.length(); k++) {
if (Character.isAlphabetic(str.charAt(k))) {
break;
}
}
System.out.print(str.charAt(k));
}
}
}
}
} else {
if (str.charAt(i) == '!') {
System.out.println();
}
}
}
if (scanner.hasNext())
System.out.println();
}
scanner.close();
}
}
private static int[] findNumber(String str, int startIndex) {
int[] array = new int[2];
int i = startIndex;
int sumOfDigit = 0;
for (; i < str.length(); i++) {
if (Character.isDigit(str.charAt(i))) {
sumOfDigit += (int) (str.charAt(i) - '0');
} else
break;
}
if (i == str.length() || sumOfDigit == 0) {
array[0] = -1;
array[1] = -1;
} else {
array[0] = sumOfDigit;
array[1] = i;
}
return array;
}
private static Scanner scanner = new Scanner(System.in);
//private static Scanner scanner = fileFactory.scanner();
}