fork download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. int cnt =0;
  7.  
  8. int recursion(const char *s, int l, int r){
  9. cnt++;
  10. if(l >= r){
  11. return 1;
  12. } else if(s[l] != s[r]) {
  13. return 0;
  14. } else{
  15. return recursion(s, l+1, r-1);
  16. }
  17. }
  18.  
  19. int isPalindrome(const char *s){
  20. return recursion(s, 0, strlen(s)-1);
  21. }
  22.  
  23. int main(){
  24. int num;
  25. cin>>num;
  26.  
  27. string str;
  28. while(num--){
  29. cin>>str;
  30.  
  31. int result = isPalindrome(str.c_str());
  32.  
  33. //1번 printf
  34. printf("%d %d\n", result, cnt);
  35.  
  36. //2번 cout
  37. // cout<<isPalindrome(str.c_str())<<' '<<cnt<<endl;
  38. cnt=0;
  39. }
  40.  
  41. }
Success #stdin #stdout 0.01s 5516KB
stdin
5
AAA
ABBA
ABABA
ABCA
PALINDROM
stdout
1 2
1 3
1 3
0 2
0 1