题目链接:点击打开链接
题解思路:我们枚举公比跟首项然后比较是否跟"xry"或"yrx"匹配就行了.
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mx = 1e4+10;
int n,a,b;
char str[mx],c[mx];
const char s[2][4] = {"yrx","xry"};
bool check(char *p)
{
for(int i=0;i<2;i++)
if(!strcmp(p,s[i])) return 1;
return 0;
}
int main()
{
int t;
scanf("%d",&t);
//freopen("1in","r",stdin);
while(t--){
char ch;
scanf("%s",str+1);
int ans = 0;
int len = strlen(str+1);
c[3] = 0;
for(int i=2;i*i<=len;i++){
for(int j=1;j*i*i<=len;j++){
c[0] = str[j];
c[1] = str[j*i];
c[2] = str[j*i*i];
if(check(c)) ans++;
}
}
printf("%d\n",ans);
}
return 0;
}