判断满足条件的三位数

Posted 2018jason

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断满足条件的三位数相关的知识,希望对你有一定的参考价值。

https://pintia.cn/problem-sets/12/problems/351

 1 int search(int n)
 2 {
 3     int count = 0;
 4     int num_sqrt; //平方根的整数部分
 5     int single, ten, hundred;
 6     for (int i = 101; i <= n; i++)
 7     {
 8         num_sqrt = (int)sqrt(i);
 9         if (i == num_sqrt * num_sqrt)
10         {
11             single = i % 10;
12             ten = i % 100 / 10;
13             hundred = i / 100;
14             if (single == ten || single == hundred || ten == hundred)
15             {
16                 count++;
17             }
18         }
19     }
20 
21     return count;
22 }

 

以上是关于判断满足条件的三位数的主要内容,如果未能解决你的问题,请参考以下文章