Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
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
Archives
Today
Total
관리 메뉴

dh-winternagi 님의 블로그

(25501) 재귀의 귀재 본문

백준 (C++)/Solve

(25501) 재귀의 귀재

dh-winternagi 2026. 4. 17. 08:00

https://www.acmicpc.net/problem/25501

단계별로 풀어보기

19단계(재귀) 3번째

 

 

 

#include <iostream>
using namespace std;

int main() 
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  string s;
  int cnt;
  
  auto pal= [&](auto& self, int l, int r) -> int {
    cnt++;
    
    if(l>=r)  return 1;
    else if(s[l]!=s[r])  return 0;
    else return self(self, l+1, r-1);
  };
  
  int T;
  
  cin >> T;
  
  while(T--){
    string S;
    
    cin >> S;
    
    s= S;
    cnt= 0;
    
    cout << pal(pal, 0, s.length()-1) << " " << cnt << "\n";
  }
  
  return 0;
}

'백준 (C++) > Solve' 카테고리의 다른 글

(4779) 칸토어 집합  (0) 2026.04.17
(24060) 알고리즘 수업 - 병합 정렬 1  (0) 2026.04.17
(10870) 피보나치 수 5  (0) 2026.04.16
(27433) 팩토리얼 2  (0) 2026.04.16
(20920) 영단어 암기는 괴로워  (0) 2026.04.16