import java.util.*;
class Main{
public static char[] solution(String input){
char[] in_char = input.toCharArray();
for(int i=0;i<input.length();i++){
char x =input.charAt(i);
if((x>=65&&x<=90) ||(x>=97&&x<=122) )
in_char[input.length()-i]=x;
else in_char[i]=x;
}
return in_char;
}
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
String input = kb.next();
System.out.println(solution(input));
}
}
in_char[input.length()-i-1]=x;
import java.util.*;
class Main{
public static char[] solution(String input){
char[] in_arr = new char[input.length()];
for(int i=0;i<input.length();i++){
char x =input.charAt(i);
if( !(x>=65&&x<=90) && !(x>=97&&x<=122) ){
in_arr[i]=x;
}
}
for(int i=0;i<input.length();i++){
char y =input.charAt(i);
if( (y>=65&&y<=90) || (y>=97&&y<=122)) {
for(int j=input.length()-1;j>=0;j--){
if(in_arr[j]==0){
in_arr[j]=y;
break;
}
}//for j
} //if
}//for i
return in_arr;
}
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
String input = kb.next();
System.out.println(solution(input));
}
}
✔ 강의 답
import java.util.*;
public class Main{
public static String solution(String input){
String answer;
char[] s = input.toCharArray();
int lt=0, rt=s.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;
rt--;
lt++;
}
}
answer = String.valueOf(s);
return answer;
}
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
String input = kb.next();
System.out.println(solution(input));
}
}