求助(玄关,只要提供错误+改正方法就关)
查看原帖
求助(玄关,只要提供错误+改正方法就关)
608648
gaoju楼主2025/1/26 11:48

样例没过。

#include<bits/stdc++.h>
using namespace std;
string s;
int ans = 0;
int n;
bool hv(string a)
{
	string b = a;
	reverse(b.begin(),b.end());
//	cout << a << " " << b << endl;
	if(a == b)
	{
		return true;
	}
	return false;
}
void f(int i,int x)
{
	string st;
	st = "";
	if(i + x >= n)
	{
		for(int j = i; j < n - 1; j++)
		{
			st += s[j];
		}
	}
	for(int j = i; j < i + x; j++)
	{
		st += s[j];
	}
	bool t = hv(st);
	if(t)
	{
//		cout << st << endl;
		ans++;
	}
	if(i + x < n)
	{
		f(i + x,x + 1);
	}
	return ;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> s;
	n = s.size();
	f(0,1);
	cout << ans;
    return 0;
}

测评记录

2025/1/26 11:48
加载中...