1040.有几个PAT

xiaoxiao2021-02-28  53

有两个要注意的点,一开始没有注意到要取1000000007的余,后来在结果处改正,可是还是有两个点过不去,应该是int的取值范围存不下的原因,所以改成了在计算过程中取余即可。

#include <iostream> using namespace std; int main() { string str; cin >> str; int numT = 0; int numAT = 0; int numPAT = 0; for(int i = str.length() - 1; i >= 0; i--) { if(str[i] == 'T') { numT++; } else if(str[i] == 'A') { numAT = (numAT + numT) % 1000000007; } else if(str[i] == 'P') { numPAT = (numPAT + numAT) % 1000000007; } } cout << numPAT; return 0; }
转载请注明原文地址: https://www.6miu.com/read-2631433.html

最新回复(0)