zoukankan      html  css  js  c++  java
  • 7744问题

     方法一:

    注意浮点数可能存在在的误差

    #include"iostream"
    #include"cmath"
    using namespace std; 
    
    int main()
    {
        for(int a=1;a<=9;a++){
            for(int b=0;b<=9;b++){
                int n=a*1100+b*11;                //aabb数 
                int m=floor(sqrt(n)+0.5);
                if(m*m == n)printf("%d
    ",n);     //不能用if(sqrt(n))==floor(sqrt(n)))  printf("%d
    ",n),因为浮点数的运算可能存在误差    
            }
        }
        return 0;
    }

    此处0.5也会受到浮点误差的影响

    方法二:

     枚举,利用了break 与 continue。

    #include"iostream"
    #include"cmath"
    using namespace std; 
    
    int main()
    {
        for(int x=1;;x++)
        {
            int n=x*x;
            if(n < 1000) continue;
            if(n > 9999) break;
            int hi = n / 100;
            int lo = n % 100;
            if(hi/10 == hi%10 && lo/10 == lo%10)printf("%d
    ",n);
        }
        return 0;
    }
    柳暗花明又一村
  • 相关阅读:
    接口
    多态
    封装
    初识继承
    对象的行为
    类、对象、包
    Java方法
    winform 报表的基本使用
    oracle配合C#的使用
    sql面试语句与后台调用js提示语句
  • 原文地址:https://www.cnblogs.com/ucandoit/p/8228316.html
Copyright © 2011-2022 走看看