第21480题 单选题
统计小于N的神奇数字的C++程序横线处应填入的代码是?

2025是个神奇的数字,因为它是由两个数20和25拼接而成,而且2025=(20+25)²。小杨决定写个程序找找小于N的正整数中共有多少这样神奇的数字。下面程序横线处应填入的是:

#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;
}
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析