Fxx and string
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 507 Accepted Submission(s): 224
Problem Description
Young theoretical computer scientist Fxx get a string which contains lowercase letters only.
The string S
contains n
lowercase letters S1S2…Sn
.Now Fxx wants to know how many three tuple (i,j,k)
there are which can meet the following conditions:
1、i,j,k
are adjacent into a geometric sequence.
2、Si=
'y
',Sj=
'r
',Sk=
'x
'.
3.Either j|i or j|k
Input
In the first line, there is an integer T(1≤T≤100)
indicating the number of test cases.
T
lines follow, each line contains a string, which contains only lowercase letters.(The length of string will not exceed 10000
).
Output
For each case, output the answer.
Sample Input
2
xyyrxx
yyrrxxxxx
Sample Output
2
Source
题意:
题解:给你一个字符串暴力求 有多少组 ‘y’ ‘r’ ‘x’ 位置成等比数列 注意逆序!
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
int t;
char a[];
int main()
{
scanf("%d",&t);
for(int i=;i<=t;i++)
{
int sum=;
scanf("%s",a+);
int len=strlen(a+);
for(int j=;j<=len;j++)
{
if(a[j]=='y')
{
for(int k=;;k++)
{
if(j*k*k>len)
break;
if(a[j*k]=='r'&&a[j*k*k]=='x')
{
sum++;
}
}
}
if(a[j]=='x')
{
for(int k=;;k++)
{
if(j*k*k>len)
break;
if(a[j*k]=='r'&&a[j*k*k]=='y')
{
sum++;
}
}
}
}
printf("%d\n",sum);
}
return ;
}