国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1093. Count PAT's (25)

2019-11-11 06:51:10
字體:
來源:轉載
供稿:網友

The string APPAPT contains two PAT’s as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.

Now given any string, you are supposed to tell the number of PAT’s contained in the string.

Input Specification:

Each input file contains one test case. For each case, there is only one line giving a string of no more than 105 characters containing only P, A, or T.

Output Specification:

For each test case, PRint in one line the number of PAT’s contained in the string. Since the result may be a huge number, you only have to output the result moded by 1000000007.

Sample Input: APPAPT Sample Output: 2

#include<cstdio>#include<cstring>const int maxn=100010;const int MOD=1000000007;char a[maxn];int leftNumP[maxn]={0};int main(){ scanf("%s",a); int len=strlen(a); for(int i=0;i<len;i++){ if(i>0){ leftNumP[i]=leftNumP[i-1]; } if(a[i]=='P') leftNumP[i]=leftNumP[i-1]+1; } int cntt=0,ans=0; for(int i=len-1;i>=0;i--){ if(a[i]=='T') cntt++; if(a[i]=='A'){ ans=(ans+leftNumP[i]*cntt)%MOD; } } printf("%d/n",ans);// long long cnt=0;// for(int i=0;i<len;i++){// if(a[i]=='P'){// for(int j=i+1;j<len;j++){// if(a[j]=='A'){// for(int k=j+1;k<len;k++){// if(a[k]=='T'){// cnt++;// }// }// }// }// }// }// long long cnt=0,cntp=0;// for(int i=0;i<len;i++){// if(a[i]=='P') cntp++;// if(a[i]=='A'){// long long cntt=0;// for(int j=i+1;j<len;j++){// if(a[j]=='T') cntt++;// }// cnt=(cnt+cntp*cntt)%MOD;// }// }// printf("%lld/n",cnt); return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 塔城市| 武威市| 德州市| 玉山县| 张家港市| 察隅县| 永善县| 桓仁| 绥中县| 高州市| 全南县| 万载县| 磴口县| 公主岭市| 岳阳市| 黑山县| 紫云| 将乐县| 河北省| 渭南市| 安吉县| 丹棱县| 娱乐| 黄浦区| 陈巴尔虎旗| 宁远县| 察哈| 旬阳县| 手游| 西宁市| 安陆市| 无锡市| 谢通门县| 江安县| 沈阳市| 色达县| 泾源县| 张家川| 康保县| 高尔夫| 高尔夫|