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

1042 字符统计 更多...

函数

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

详细描述

1042 字符统计

函数说明

◆ main()

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

在文件 pat.cpp1349 行定义.

1349 {
1350 auto *str = new char[1001];
1351 cin.getline(str, 1001);
1352 map<char, int> m;
1353 int maximum = 0;
1354 for(int i = 0; i < strlen(str); ++i) {
1355 char ch = tolower(str[i]);
1356 if(isalpha(ch) != 0) {
1357 m[ch]++;
1358 maximum = max(maximum, m[ch]);
1359 }
1360 }
1361 for(auto [ch, cnt]: m) {
1362 if(cnt == maximum) {
1363 cout << ch << ' ' << cnt;
1364 break;
1365 }
1366 }
1367 delete[] str;
1368 return 0;
1369 }

被这些函数引用 TEST().

◆ TEST()

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

在文件 pat_test.cpp645 行定义.

645 {
646 istringstream in("This is a simple TEST. There ARE numbers and other symbols 1&2&3...........");
647 auto out = ostringstream();
648 main(in, out);
649 const auto ans = out.str();
650 ASSERT_EQ("e 7", out.str());
651 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().