题目链接:点击打开链接
1001-Find Q
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others)
Total Submission(s): 342 Accepted Submission(s): 190
Problem Description
S consisting of lowercase English letters.
He wants to find all the continous substrings of
S, which only contain the letter 'q'. But this string is really really long, so could you please write a program to help him?
Input
T(1≤T≤10), denoting the number of test cases.
In each test case, there is a string
S, it is guaranteed that
S only contains lowercase letters and the length of
S is no more than
100000.
Output
S, which only contain the letter 'q'.
Sample Input
2 qoder quailtyqqq
Sample Output
1 7
题解:最后就因为那个 %I64dI(%lld)被人给 hack 了
#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
char s[100010];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",s);
LL cnt=0,ans=0;
for(int i=0;s[i];i++)
{
if(s[i]=='q')
{
cnt++;
}
else
{
if(cnt)
ans=ans+cnt*(cnt+1)/2;
cnt=0;
}
}
if(cnt) ans=ans+cnt*(cnt+1)/2;
printf("%I64d\n",ans);
}
return 0;
}
/*
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
#define CLR(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
int main()
{
int n;scanf("%d",&n);
while(n--)
{
char ch[100100];
scanf("%s",ch);
long long t=0,ans=0;
int ll=strlen(ch);
for (int i=0;i<ll;i++)
{
if(ch[i]=='q')
t++;
else
t=0;
ans+=t;
}
printf("%lld\n",ans);
}
return 0;
}*/