A、Find Q
Accepts: 392
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 262144/131072 K (Java/Others)
1 7
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 #include <cmath> 7 #include <time.h> 8 #include <string> 9 #include <map> 10 #include <stack> 11 #include <vector> 12 #include <set> 13 #include <queue> 14 #define inf 0x7fffffff 15 #define mod 10000 16 #define met(a,b) memset(a,b,sizeof a) 17 typedef long long ll; 18 using namespace std; 19 const int N = 100; 20 const int M = 100000; 21 const int INF = 0x3f3f3f3f; 22 int x; 23 24 char s[100002]; 25 long long int a[1000]; 26 27 int main() 28 { 29 long long int sum = 0; 30 int t; 31 scanf("%d", &t); 32 while(t--) 33 { 34 scanf("%s", s); 35 int len = strlen(s); 36 long long int cnt = 0; 37 sum = 0; 38 for(int i = 0; i < len; i++) 39 { 40 if(s[i] == 'q') 41 { 42 cnt++; 43 }else if(cnt > 0){ 44 sum += cnt*(cnt+1)/2; 45 cnt = 0; 46 } 47 } 48 if(cnt > 0) sum += cnt*(cnt+1)/2; 49 printf("%lld ", sum); 50 } 51 }
Abelian Period
Accepts: 288
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 262144/131072 K (Java/Others)