1093. Count PAT's (25)
时间限制120 ms
内存限制65536 kB
代码长度限制16000 B
判题程序Standard作者CAO, Peng
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 105characters 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:APPAPTSample Output:2看看一串按着原来的顺序的不一定要相连的能有几个PAT;
输出几个;如果这个答案很大的话这里是大于或等于1000000007,就要对1000000007取模%mod;
我下面的代码str[2]代表当前index至后面包括index有多少个T;
str[1]代表当前index至后面包括index有多少个AT;
str[0]代表当前index至后面包括index有多少个PAT;
误认为溢出才输出1000000007,并且最开始+str[1]*s[0];这个思想是错误的。比如PATPAT这里只有4个如果用乘的化就会变成5个。
评测结果
时间 | 结果 | 得分 | 题目 | 语言 | 用时(ms) | 内存(kB) | 用户 |
---|---|---|---|---|---|---|---|
8月19日 09:36 | 答案正确 | 25 | 1093 | C++ (g++ 4.7.2) | 5 | 516 | datrilla |
测试点
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 1 | 180 | 14/14 |
1 | 答案正确 | 1 | 436 | 1/1 |
2 | 答案正确 | 5 | 500 | 2/2 |
3 | 答案正确 | 5 | 516 | 4/4 |
4 | 答案正确 | 5 | 436 | 4/4 |
#include<iostream> #include<string> using namespace std; int main() { string patstr; bool Flag = true; int str[3] = { 0 }; int index; getline(cin, patstr); for (index = patstr.size() - 1; index >= 0 && Flag; index--) { if (patstr[index] == 'T') str[2]++; else if (patstr[index] == 'A') str[1] += str[2]; else { str[0] += str[1]%1000000007; str[0]%= 1000000007; } } cout << str[0] << endl; system("pause"); return 0; }