<>string Class optional byte (char) As its character type , that string It's actually a char array .

<> adopt string Class

Example
// string constructor #include <iostream> #include <string> int main () { std::
strings0 ("Initial string"); // constructors used in the same order as
described above: std::string s1; std::string s2 (s0); std::string s3 (s0, 8, 3);
std::string s4 ("A character sequence"); std::string s5 ("Another character
sequence", 12); std::string s6a (10, 'x'); std::string s6b (10, 42); // 42 is
the ASCII code for '*' std::string s7 (s0.begin(), s0.begin()+7); std::cout <<
"s1: " << s1 << "\ns2: " << s2 << "\ns3: " << s3; std::cout << "\ns4: " << s4 <<
"\ns5: " << s5 << "\ns6a: " << s6a; std::cout << "\ns6b: " << s6b << "\ns7: " <<
s7<< '\n'; return 0; }
output
s1: s2: Initial string s3: str s4: A character sequence s5: Another char s6a:
xxxxxxxxxx s6b: ********** s7: Initial
<> adopt void push_back (char c); Convert

effect : Will character c Attach to string End of , Increase its length by one .
string g[N]; string s; s.push_back(g[i][j]);
<> Example : Moo encryption (USACO 2015 US Open Bronze)

Many people don't know , Cows love jigsaw puzzles , Especially word puzzles .

Farmer John's cow recently invented an interesting “ Word finder ” Jigsaw puzzle .

An example of this puzzle is :
USOPEN OOMABO MOOMXO PQMROM
As a cow , The only words they are interested in are MOO, It can move horizontally several times in the puzzle , vertical ,45 Degree slash or 135 Degree slash appears .

In the above example ,MOO A total of 6 second .

Farmer John is also a puzzle fan , Because the cows don't want him to solve it before them “ Word finder ” Jigsaw puzzle , So they use ” Replace password “ Encrypted content .

The “ Replace password ” Replaced each letter in the alphabet with a different letter .

for example , A A A Can map to X X X, B B B Can map to A A A, And so on .

No letters mapped to themselves , No two letters map to the same letter ( Otherwise the solution will be ambiguous ).

Unfortunately , The cow forgot the specific encryption method to replace the password .

Please help them determine if decryption is done with the appropriate replacement password , The maximum possible existence in the puzzle MOO number .

Input format
The first row contains N , M N,M N,M, Indicates that the size of the puzzle is N N N that 's ok M M M column .

next N N N that 's ok , Each row contains M M M Capital letters , Describe the encrypted puzzle .

Output format
Output if decrypted with appropriate alternate password , The maximum possible existence in the puzzle MOO number .

Data range
1 ≤ N , M ≤ 50 1≤N,M≤50 1≤N,M≤50
sample input :
4 6 TAMHGI MMQVWM QMMQSM HBQUMQ
sample output :
6
Example explanation
In this example , M M M and O O O Replaced by Q Q Q and M M M.

This decryption can exist at most 6 individual MOO.

This topic is enumeration + Hash
Answer:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #
include <unordered_map> using namespace std; const int N = 55; int n, m; string
g[N]; int main() { cin >> n >> m; for (int i = 0; i < n; i ++) cin >> g[i]; int
dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
unordered_map<string, int> hash; for (int i = 0; i < n; i ++) { for (int j = 0;
j< m; j ++) { for (int k = 0; k < 8; k ++) { int x = i, y = j; string s(1, g[x][
y]); bool flag = true; for (int u = 0; u < 2; u ++) { x += dx[k], y += dy[k]; if
(x < 0 || x >= n || y < 0 || y >= m) { flag = false; break; } s += g[x][y]; } if
(flag && s[0] != s[1] && s[1] == s[2] && s[0] != 'M' && s[1] != 'O') hash[s] ++;
} } } int res = 0; for (auto& [k, v] : hash) res = max(res, v); cout << res <<
endl; return 0; }

Technology