-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJava_17413.java
More file actions
37 lines (31 loc) · 1.2 KB
/
Java_17413.java
File metadata and controls
37 lines (31 loc) · 1.2 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
package src;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Java_17413 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();
StringBuilder flipWord = new StringBuilder();
boolean isTag =false;
int startWordIdx=-1;
for(int i =0;i<input.length();i++){
if(!isTag){
if(startWordIdx==-1) startWordIdx=i;
if(input.charAt(i)==' ' || i==input.length()-1 ||input.charAt(i)=='<'){
if(i==input.length()-1) flipWord.append(input.charAt(i));
for(int j=i-1; j>=startWordIdx;j--){
flipWord.append(input.charAt(j));
}
if(input.charAt(i)==' ') flipWord.append(' ');
startWordIdx=-1;
}
}
if(input.charAt(i)=='<') isTag=true;
if(isTag) flipWord.append(input.charAt(i));
if(input.charAt(i)=='>') isTag=false;
}
System.out.println(flipWord);
br.close();
}
}