酷代码 AI
菜单
服务商

舞蹈班排队难题:根据身高算出婷婷前后排队位置(附C++代码)

```cpp #include <iostream> using namespace std; int main() { int n; cin >> n; int heights[n]; for (int i = 0; i < n; i++) { cin >> heights[i]; } int ttingHeight; cin >> ttingHeight; int frontCount = 0, backCount = 0; for (int i = 0; i < n; i++) { if (heights[i] < ttingHeight) { frontCount++; } else if (heights[i] == ttingHeight) { backCount++; } } int frontPosition = frontCount + 1; int backPosition = frontCount + backCount; cout << frontPosition << " " << backPosition << endl; // 额外注意: // 1. 注意输入数据的合法性检查。 // 2. 考虑使用更高效的数据结构,如排序后的数组。 // 3. 对于大规模数据,要注意算法的时间和空间复杂度。 return 0; } ``` ######[AI写代码神器 | 263点数解答 | 2025-01-14 10:49:37]

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