题库 / 3070906. 补全代码:for 循环(2025-03)
3070906. 补全代码:for 循环(2025-03)
题目描述
是个神奇的数字,因为它是由两个数和拼接而成,而且。小杨决定写个程序找找小于的正整数中共有多少这样神奇的数字。下面程序横线处应填入的是()。
#include <string>
int count_miracle(int N) {
int cnt = 0;
for (int n = 1; n * n < N; n++) {
int n2 = n * n;
std::string s = std::to_string(n2);
for (int i = 1; i < s.length(); i++)
if (s[i] != '0') {
std::string sl = s.substr(0, i);
std::string sr = s.substr(i);
int nl = std::stoi(sl);
int nr = std::stoi(sr);
if (_________) // 在此处填入选项
cnt++;
}
}
return cnt;
}
作答说明
单选题:在选项里选出唯一正确的一项,提交后立即判定。答对得满分,答错可以重新提交(两次提交之间需要间隔 20 秒)。
题目来源
CCF GESP 2025 年 3 月认证 C++ 7 级试题,第 8 题。