Taene's
[백준] 브론즈2-재귀의 귀재 C++ 25501번 본문
https://www.acmicpc.net/problem/25501
25501번: 재귀의 귀재
각 테스트케이스마다, isPalindrome 함수의 반환값과 recursion 함수의 호출 횟수를 한 줄에 공백으로 구분하여 출력한다.
www.acmicpc.net
#include <string>
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
int countP;
int recursion(const char* s, int len, int r)
{
countP++;
if (len >= r) return 1;
else if (s[len] != s[r]) return 0;
else return recursion(s, len + 1, r - 1);
}
int isPalindrome(const char* s)
{
return recursion(s, 0, strlen(s) - 1);
}
int main()
{
int t;
cin >> t;
while (t--)
{
char s[1001];
cin >> s;
cout << isPalindrome(s) << ' ' << countP << '\n';
countP = 0;
}
return 0;
}
접근방법: 재귀함수를 이해하고 사용하자
'백준 > 브론즈' 카테고리의 다른 글
[백준] 브론즈1-일곱 난쟁이 C++ 2309번 (0) | 2025.02.21 |
---|---|
[백준] 브론즈1-평균 C++ 1546번 (0) | 2024.02.26 |
[백준] 브론즈3-수학-곱셈 C++ 2588번 (0) | 2023.08.23 |
[백준] 브론즈V-킹, 퀸, 룩, 비숍, 나이트, 폰 C++ 3003번 (0) | 2023.08.23 |
[백준] 브론즈V-Shares C++ 3733번 (0) | 2023.08.23 |