import java.util.*;
class Main {
public String solution(String x) {
String answer = "";
char[] s = x.toCharArray();
int lt = 0, rt = x.length() - 1;
while (lt < rt) {
if (!((s[lt] >= 'A' && s[lt] <= 'Z') || (s[lt] >= 'a' && s[lt] <= 'z'))) {
lt++;
continue;
} else if (!((s[rt] >= 'A' && s[rt] <= 'Z') || (s[rt] >= 'a' && s[rt] <= 'z'))) {
rt--;
continue;
} else {
char tmp = s[lt];
s[lt] = s[rt];
s[rt] = tmp;
lt++;
rt--;
}
}
answer = String.valueOf(s);
return answer;
}
public static void main(String[] args) {
Main T = new Main();
Scanner kb = new Scanner(System.in);
System.out.println(T.solution(kb.nextLine()));
}
}
import java.util.*;
class Main {
public String solution(String x) {
String answer = "";
char[] s = x.toCharArray();
int lt = 0, rt = x.length() - 1;
while (lt < rt) {
if (!Character.isAlphabetic(s[lt])) {
lt++;
} else if (!Character.isAlphabetic(s[rt])) {
rt--;
} else {
char tmp = s[lt];
s[lt] = s[rt];
s[rt] = tmp;
lt++;
rt--;
}
}
answer = String.valueOf(s);
return answer;
}
public static void main(String[] args) {
Main T = new Main();
Scanner kb = new Scanner(System.in);
System.out.println(T.solution(kb.nextLine()));
}
}
Character.isAlphabetic(s[rt])
'알고리즘 > JAVA' 카테고리의 다른 글
7. 회문 문자열 (0) | 2021.08.31 |
---|---|
6. 중복문자제거 (0) | 2021.08.31 |
4. 단어 뒤집기 (0) | 2021.08.31 |
3. 문장 속 단어 (0) | 2021.08.22 |
2. 대소문자 변환 (0) | 2021.08.22 |
댓글