problemscpp
A collection of my answers to algorithm problems in c++.
函数
pat::b::b1040 命名空间参考

1040 有几个PAT 更多...

函数

int main (istream &cin, ostream &cout)
 
 TEST (b1040, case1)
 

详细描述

1040 有几个PAT

函数说明

◆ main()

int pat::b::b1040::main ( istream &  cin,
ostream &  cout 
)

在文件 pat.cpp1296 行定义.

1296 {
1297 string str;
1298 cin >> str;
1299 vector<unsigned long long> p(str.length(), 0);
1300 vector<unsigned long long> t(str.length(), 0);
1301 unsigned long long current_p = 0;
1302 for(int i = 0; i < p.size(); ++i) {
1303 p[i] = current_p;
1304 if(str[i] == 'P') {
1305 current_p++;
1306 }
1307 }
1308 unsigned long long current_t = 0;
1309 for(int i = t.size() - 1; i >= 0; --i) {
1310 t[i] = current_t;
1311 if(str[i] == 'T') {
1312 current_t++;
1313 }
1314 }
1315 unsigned long long ans = 0;
1316 for(int i = 0; i < p.size(); i++) {
1317 if(str[i] == 'A') {
1318 ans += p[i] * t[i] % 1000000007;
1319 ans %= 1000000007;
1320 }
1321 }
1322 cout << ans;
1323 return 0;
1324 }

被这些函数引用 TEST().

◆ TEST()

pat::b::b1040::TEST ( b1040  ,
case1   
)

在文件 pat_test.cpp617 行定义.

617 {
618 istringstream in("APPAPT");
619 auto out = ostringstream();
620 main(in, out);
621 const auto ans = out.str();
622 ASSERT_EQ("2", out.str());
623 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().