์ค๋์ ๋ฌธ์ >> 31458๋ฒ: !!์ด์ฝ๋ฆฟ ์ค๋ ์ฃผ์!!
[ ์๊ฐ ํ๋ฆ ]
!๊ฐ ์ฌ๋ผ์ง ๋๊น์ง ๋ฐ๋ณตํ๋ฉด์ ์ฐ์ ์์๋๋ก ๋ฌธ์์ด์ ๋์ฒดํ๋ฉด ๋ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ!
[ Java ]
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
sc.nextLine();
for(int i=0; i<T; i++){
String word = sc.nextLine();
while (word.contains("!")) {
if (word.contains("0!")) {
word = word.replace("0!", "1");
} else if (word.contains("!0")) {
word = word.replace("!0", "1");
} else if (word.contains("1!")) {
word = word.replace("1!", "1");
} else if (word.contains("!1")) {
word = word.replace("!1", "0");
}
}
System.out.println(word);
}
sc.close();
}
}
์ฒ์ ์ซ์๋ฅผ ์ ๋ ฅ ๋ฐ์ ๋, sc.nextInt()๋ฅผ ์ฌ์ฉํ๋ฉด ๊ฐํ๋ฌธ์๋ (\n) ๋จ์์๊ฒ ๋๋ค..!
๊ทธ๋์ ๊ทธ ๋ค์ ๋ฌธ์์ด(word)์ ์ ๋ ฅ ๋ฐ๊ธฐ ์ ์ sc.nextLine();์ ์จ์ฃผ์ด์ผ
๋จ์์๋ ๊ฐํ๋ฌธ์๊ฐ ์ฒ๋ฆฌ๋์ด ์ฌ๋ฐ๋ฅด๊ฒ for๋ฌธ ์์์ ์ ๋ ฅ์ ๋ฐ์ ์ ์๊ฒ ๋๋ ๊ฒ์ด๋ค~
'TIL๐ฅ > ์ฝ๋ฉํ ์คํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํญํด99ํด๋ฝ] Java ๋น๊ธฐ๋_Day 5 Implement Stack using Queues (0) | 2025.04.04 |
---|---|
[ํญํด99ํด๋ฝ] Java ๋น๊ธฐ๋_Day 4 Implement Queue using Stacks (0) | 2025.04.03 |
[ํญํด99ํด๋ฝ] Java ๋น๊ธฐ๋_Day 2 ๋ฌธ์์ด ๋ถ์ (0) | 2025.04.01 |
[ํญํด99ํด๋ฝ] Java ๋น๊ธฐ๋_Day 1 ๋ช ๋ น ํ๋กฌํํธ, ํฐ๋ฆฐ๋๋กฌ (0) | 2025.03.31 |
[๋ฐฑ์ค] 15894๋ฒ - ์ํ์ ์ฒด์ก๊ณผ๋ชฉ ์ ๋๋ค (1) | 2024.01.08 |
๋๊ธ