-
Notifications
You must be signed in to change notification settings - Fork 0
/
J03029_ChuanHoaCau.java
46 lines (44 loc) · 1.73 KB
/
J03029_ChuanHoaCau.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
import java.io.*;
import java.math.*;
import java.util.*;
public class J03029_ChuanHoaCau {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextLine()) {
String s = sc.nextLine();
s = s.toLowerCase();
StringTokenizer ss = new StringTokenizer(s);
Vector<String> v = new Vector<>();
while (ss.hasMoreTokens()) {
v.add(ss.nextToken());
}
int n = v.size();
if (v.elementAt(n - 1).charAt(v.elementAt(n - 1).length() - 1) != '.' && v.elementAt(n - 1).charAt(v.elementAt(n - 1).length() - 1) != '?' && v.elementAt(n - 1).charAt(v.elementAt(n - 1).length() - 1) != '!') {
String s2 = v.elementAt(n - 1);
s2 += ".";
v.removeElementAt(n - 1);
v.add(s2);
}
if (v.elementAt(n - 1).equals(".") || v.elementAt(n - 1).equals("!") || v.elementAt(n - 1).equals("?")) {
String kitu = v.elementAt(n - 1);
v.removeElementAt(n - 1);
n = v.size();
String s2 = v.elementAt(n - 1);
s2 += kitu;
v.removeElementAt(n - 1);
v.add(s2);
}
char x = v.elementAt(0).charAt(0);
if (x >= 'a' && x <= 'z') {
x = (char) (x - 32);
}
String xx = v.elementAt(0).substring(1);
xx = x + xx + " ";
for (int i = 1; i < v.size() - 1; i++) {
xx += v.elementAt(i) + " ";
}
xx += v.elementAt(v.size() - 1);
System.out.println(xx);
}
}
}