酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

核桃月赛升级为周赛!C++代码助你算第n周比赛场数

以下是用 C++ 语言解决此问题的代码: ```cpp #include <iostream> int countContests(int n) { if (n == 1) { return 3; } int numNewbie = (n - 1) / 1; int numCSPJ = (n - 1) / 2; int numCSPS = (n - 1) / 3; int total = 0; if (numNewbie > 0 && n % 1 == 0) { total++; } if (numCSPJ > 0 && n % 2 == 0) { total++; } if (numCSPS > 0 && n % 3 == 0) { total++; } return total; } int main() { int n; std::cout << "请输入周数: "; std::cin >> n; int contests = countContests(n); std::cout << "第 " << n << " 周将举办 " << contests << " 场比赛。" << std::endl; return 0; } ``` ######[AI写代码神器 | 281点数解答 | 2024-09-07 23:37:15]

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