01-08 08:57
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[Algorithm]์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”_5 ํŠน์ • ๋ฌธ์ž ๋’ค์ง‘๊ธฐ ๋ณธ๋ฌธ

Algorithm/Java

[Algorithm]์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”_5 ํŠน์ • ๋ฌธ์ž ๋’ค์ง‘๊ธฐ

miinsun 2022. 1. 2. 23:08

 

๐Ÿ’ฌ ๋ฌธ์ œ ์„ค๋ช…

์˜์–ด ์•ŒํŒŒ๋ฒณ๊ณผ ํŠน์ˆ˜๋ฌธ์ž๋กœ ๊ตฌ์„ฑ๋œ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง€๋ฉด ์˜์–ด ์•ŒํŒŒ๋ฒณ๋งŒ ๋’ค์ง‘๊ณ , ํŠน์ˆ˜๋ฌธ์ž๋Š” ์ž๊ธฐ ์ž๋ฆฌ์— ๊ทธ๋Œ€๋กœ ์žˆ๋Š” ๋ฌธ์ž์—ด์„ ๋งŒ๋“ค์–ด ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์„ธ์š”.

 

 

๐Ÿ”จ ์ž…์ถœ๋ ฅ ์˜ˆ

์ž…๋ ฅ - ์ฒซ ์ค„์— ๊ธธ์ด๊ฐ€ 100์„ ๋„˜์ง€ ์•Š๋Š” ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.

a#b!GE*T@S

์ถœ๋ ฅ - ์ฒซ ์ค„์— ์•ŒํŒŒ๋ฒณ๋งŒ ๋’ค์ง‘ํžŒ ๋ฌธ์ž์—ด์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

 
S#T!EG*b@a

โ€‹

๐Ÿ’ป Solution.java

import java.util.Scanner;
  
public class Main {
	public String solution(String str) {
		char[] chArr = str.toCharArray();
		
		int lt = 0;
		int rt = str.length() - 1;
		while(lt < rt) {
			if(!Character.isAlphabetic(chArr[lt])) {
				lt++;
			}
			else if(!Character.isAlphabetic(chArr[rt])) {
				rt--;
			}
			else{
				char tmp = chArr[lt];
				chArr[lt] = chArr[rt];
				chArr[rt] = tmp;
				
				lt++;
				rt--;
			}
		}
		
		return String.valueOf(chArr);
	}
	
	public static void main(String[] args){
		Main main  = new Main();
		Scanner sc =new Scanner(System.in);
		String str = sc.next();
		
		System.out.println(main.solution(str));
		sc.close();
		return ;
	}
}

 

Comments