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

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

1093. Count PAT's (25)

2019-11-14 08:55:01
字體:
供稿:網(wǎng)友

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;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 莱芜市| 白水县| 仙居县| 英超| 洪江市| 舟山市| 抚宁县| 潍坊市| 思南县| 临洮县| 闵行区| 南召县| 临桂县| 双牌县| 宁安市| 清流县| 缙云县| 岐山县| 南康市| 龙胜| 锦屏县| 象山县| 德保县| 吉首市| 义马市| 麻栗坡县| 安义县| 广汉市| 五峰| 尖扎县| 岗巴县| 清丰县| 巩义市| 东平县| 镇宁| 德阳市| 连州市| 山阳县| 新巴尔虎右旗| 铜山县| 莒南县|