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

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

1093. Count PAT's (25)

2019-11-11 07:24:24
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 芜湖市| 南漳县| 渭源县| 民县| 兴仁县| 民丰县| 宜都市| 凤冈县| 凤山县| 孟村| 津南区| 枣阳市| 鹤峰县| 加查县| 利川市| 东山县| 霍林郭勒市| 黑水县| 遂平县| 东辽县| 临沂市| 苏尼特右旗| 盈江县| 瓦房店市| 南漳县| 南召县| 那曲县| 肇州县| 搜索| 淮安市| 六安市| 青阳县| 高邮市| 永靖县| 桑植县| 宁晋县| 鄂托克前旗| 巫山县| 涟源市| 桐柏县| 桐柏县|