zoukankan      html  css  js  c++  java
  • 守形数

     题目截图:

     

    思路:

      首先,只有尾数为 0,1,5,6 的数才可能为守形数,所以其他可以直接排除。然后对其他的数进行判断即可。

    代码如下:

     1 /*
     2     守形数
     3 */
     4 
     5 #include <stdio.h>
     6 #include <string.h>
     7 #include <math.h>
     8 #include <stdlib.h>
     9 #include <time.h>
    10 #include <stdbool.h>
    11 
    12 int main() {
    13     int N;
    14     while(scanf("%d", &N) != EOF) {
    15         int g = N%10;                        // 提取尾数 
    16         // 只有尾数为 0,1,5,6 的数才可能为守形数
    17         if(g==1 || g==5 || g==6 || g==0) {
    18             int t = N*N;            
    19             int ans=10;                        // 用来提取低位部分 
    20             if(N > 10) {
    21                 ans = 100;
    22             } 
    23             if(t%ans == N) {                // 判断是否是守形数 
    24                 printf("Yes!
    ");
    25             } else {
    26                 printf("No!
    ");
    27             }
    28         } else {
    29             printf("No!
    ");
    30         }
    31     } 
    32 
    33     return 0;
    34 }
  • 相关阅读:
    函数递归,匿名函数
    生成器
    迭代器
    有参函数(认证功能)
    闭包函数和装饰器
    文件处理
    Celery介绍
    Redis 介绍
    GIT知识点
    前后端分离-前端配置
  • 原文地址:https://www.cnblogs.com/coderJiebao/p/HustTest14.html
Copyright © 2011-2022 走看看