酷代码 AI
菜单
服务商

C++ 实现:计算未知量比较中更开心整数数对的个数

```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; } ``` ######[AI写代码神器 | 270点数解答 | 2024-11-02 15:47:30]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]