• A1132. Cut Integer


    Cutting an integer means to cut a K digits lone integer Z into two integers of (K/2) digits long integers A and B. For example, after cutting Z = 167334, we have A = 167 and B = 334. It is interesting to see that Z can be devided by the product of A and B, as 167334 / (167 × 334) = 3. Given an integer Z, you are supposed to test if it is such an integer.

    Input Specification:

    Each input file contains one test case. For each case, the first line gives a positive integer N (≤ 20). Then N lines follow, each gives an integer Z (10 ≤ Z <2^31). It is guaranteed that the number of digits of Z is an even number.

    Output Specification:

    For each case, print a single line Yes if it is such a number, or No if not.

    Sample Input:

    3
    167334
    2333
    12345678
    

    Sample Output:

    Yes
    No
    No

    #include<iostream>
    #include<cstdio>
    using namespace std;
    long long Z;
    int num2Cut(long long Z){
        long long temp[500], bit, Z2 = Z;
        int pt = 0;
        do{
            bit = Z % 10;
            Z = Z / 10;
            temp[pt++] = bit;
        }while(Z != 0);
        long long a = 0, b = 0;
        for(int i = pt - 1; i >= pt / 2; i--){
            a = a * 10 + temp[i];
        }
        for(int i = pt / 2 - 1; i >= 0; i--){
            b = b * 10 + temp[i];
        }
        if(a*b == 0)
            return 0;
        if(Z2 % (a*b) == 0)
            return 1;
        else return 0;
    }
    int main(){
        int N;
        scanf("%d", &N);
        for(int i = 0; i < N; i++){
            scanf("%lld", &Z);
            int tag = num2Cut(Z);
            if(tag == 0)
                printf("No
    ");
            else printf("Yes
    ");
        }
        cin >> N;
        return 0;
    }
    View Code

    总结:
    1、题意:将一个位数为偶数的数字分成两半,看看这两半的乘积能不能被原数整除。
    2、注意依次取一个数的各个位,得到的数组中是倒着的,由高位到低位。
    2、在验证能否整除时,要注意被除数为0的情况。如1000被分成10和00.
  • 相关阅读:
    模型绑定
    Asp.Net MVC基础
    Entity Framework 6.x介绍
    IE内核发送ajax请求时不会将url中的参数编码
    .NET使用OpenSSL生成的pem密钥文件[1024位]
    简单测试nginx1.90做TCP协议负载均衡的功能
    《图解TCP/IP》读书笔记
    使用wireshark抓包分析浏览器无法建立WebSocket连接的问题(server为Alchemy WebSockets组件)
    wireshark常用的过滤器设置
    通过监控线程状态来保证socket服务器的稳定运行
  • 原文地址:https://www.cnblogs.com/zhuqiwei-blog/p/9553694.html
Copyright © 2020-2023  润新知