1093.Count PAT's (25)...to be continued...
2017-03-02 18:00
447 查看
1093.Count PAT’s (25)…to be continued…
pat-al-1093
2017-03-02
乙级好像有这题
暴力会超时,对于每个A,只要知道它前面多少个P和后面有多少T
-TBC-
pat-al-1093
2017-03-02
乙级好像有这题
暴力会超时,对于每个A,只要知道它前面多少个P和后面有多少T
/** * pat-al-1093 * 2017-03-02 * Cpp version * Author: fengLian_s */ #include<stdio.h> #include<string.h> #define MAX 100010 int main() { freopen("in.txt", "r", stdin); char str[MAX]; scanf("%s", str); int numOfP[MAX] = {0}; int len = strlen(str); for(int i = 0;i < len;i++) { if(i > 0 && str[i] == 'P') { numOfP[i] = numOfP[i-1]+1; } else if(i == 0 && str[i] == 'P') { numOfP[i] = 1; } else numOfP[i] = numOfP[i-1]; //printf("i: %d\n", numOfP[i]); } int numOfT = 0; int ans = 0; for(int i = len-1;i >= 0;i--) { if(i == len-1 && str[i] == 'T') numOfT = 1; else if(i < len-1 && str[i] == 'T') numOfT++; else if(str[i] == 'A') { ans += (numOfT * numOfP[i]); ans %= 1000000007; } } printf("%d\n", ans); return 0; }
-TBC-
相关文章推荐
- PAT 1093. Count PAT's (25)
- 1093. Count PAT's (25)
- 1089.Insert or Merge (25)...to be continued...
- 1040. 有几个PAT(25)PAT乙级&&1093. Count PAT's (25) PAT甲级
- 1086.Tree Traversals Again (25)...to be continued...
- 1071.Speech Patterns (25)...to be continued...
- 1093. Count PAT's (25)
- 1012.The Best Rank (25)...to be continued...
- PAT 1093. Count PAT's (25) 求顺序不变的固定子序列数量
- PAT A 1093. Count PAT's (25)
- 1093. Count PAT’s (25)-统计字符串中PAT出现的个数
- 1043.Is It a Binary Search Tree (25)...to be continued...
- PAT (Advanced Level) Practise 1093 Count PAT's (25)
- 1093. Count PAT's (25)
- 1039.Course List for Student (25)...to be continued...
- 1066.Root of AVL Tree (25)...to be continued...
- PAT (Advanced Level) Practise 1093 Count PAT's (25)
- 1016.Phone Bills (25)...to be continued...
- 1047.Student List for Course (25)...to be continued...
- PAT 1093. Count PAT's (25)