728x90
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
*는 길이가 0 이상인 임의의 알파벳들로 대체될 수 있는 와일드 카드이다.
start나 end에 *이 나오기만 하면 true가 된다.
*이 안 나오는 상황에서
start와 end값이 다르면 false이다.
ex)
a*bc*a
a,a 같음
* * 나와서 바로 true
a*bca
a,a 같음
*,c 바로 true
abda
a,a 같음
b,d 다름 false
import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 1; tc <= t; tc++) {
String word = sc.next();
boolean isExist = isPalindrome(word);
if (isExist) {
System.out.println("#" + tc + " " + "Exist");
} else {
System.out.println("#" + tc + " " + "Not exist");
}
}
}
public static boolean isPalindrome(String word) {
int start = 0;
int end = word.length() - 1;
while (start <= end) {
if (word.charAt(start) == '*' || word.charAt(end) == '*') {
return true;
}
if (word.charAt(start) != word.charAt(end)) {
return false;
}
start++;
end--;
}
return true;
}
}728x90
'SW Expert Academy > SWEA D3' 카테고리의 다른 글
| [SW Expert Academy] 구구단 걷기 (D3) (0) | 2024.09.28 |
|---|---|
| [SW Expert Academy] 신뢰 (D3) (0) | 2024.09.28 |
| [SW Expert Academy] 유효기간 (D3) (0) | 2024.09.27 |
| [SW Expert Academy] 세가지 합 구하기 (D3) (0) | 2024.09.27 |
| [SW Expert Academy] 문자열 교집합 (D3) (0) | 2024.09.27 |