문제 URL : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWO6Oao6N4QDFAWw
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
문제 접근법 : 팰린드롬인지 확인하면 되는문제입니다. 왼쪽과 오른쪽 맨끝자리에서 같은지 확인하면 되기때문에
문자열의 사이즈가 홀수인지 짝수인지 판단할 필요도 없습니다.
그리고 문자가 ?라면 모든지 같다고 표현해줍니다.
소스코드 :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include <bits/stdc++.h>
using namespace std;
string s;
void input() {
cin >> s;
}
bool same(char a, char d) {
if (a == d)return true;
if (a == '?' || d == '?')return true;
return false;
}
bool ispellin(int l, int r) {
if (l > r)return true;
if (same(s[l], s[r])) return ispellin(l + 1, r - 1);
return false;
}
void solve() {
cout << (ispellin(0, s.size() - 1) ? "Exist" : "Not exist" )<< "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int test;
cin >> test;
for (int i = 1; i <= test; i++) {
input();
cout << "#" << i << " ";
solve();
}
}
|
cs |

궁금한점 혹은 모르는점 어떤 질문이든 댓글은 언제나 환영입니다.
'SWEA' 카테고리의 다른 글
[SWEA] 1252. 단순도금비용 (python) (0) | 2024.12.09 |
---|---|
[SWEA] 11387. 몬스터 사냥 (1) | 2021.08.14 |
[SWEA] 11315. 오목 판정 (0) | 2021.08.12 |
[SWEA] 1979. 어디에 단어가 들어갈 수 있을까 (0) | 2021.08.12 |
[SWEA] 11688. Calkin-Wilf tree 1 (0) | 2021.08.11 |