酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

核桃月赛将于四月开始正式升级为核桃周赛,目前已知的信息是: 每周举办一场新手赛。 隔一周举办一场csp-j赛。 隔两周举办一场csp-s赛。 特别的,第一周将同时举办三场比赛。 请你帮助 面条老师 计算出,第 n 周将举办几场比赛。(用c++语言来编写代码)

以下是用 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; } ``` [2024-09-07 23:37:15 | AI写代码神器 | 281点数解答]

相关提问