```cpp #include <iostream> #include <string> int countHappyPairs(int n, std::string &c) { int count = 0; for (int i = 1; i < n; ++i) { for (int j = i + 1; j <= n; ++j) { bool isHappy = true; for (int k = i; k < j - 1; ++k) { if ((c[k - 1] == '>' && c[k] == '<') || (c[k - 1] == '<' && c[k] == '>')) { isHappy = false; break; } } if (isHappy) { count++; } } } return count; } int main() { int t; std::cin >> t; while (t--) { int n; std::cin >> n; std::string c; std::cin >> c; std::cout << countHappyPairs(n, c) << std::endl; } return 0; } ``` [2024-11-02 15:47:30 | AI写代码神器 | 270点数解答]