zoukankan      html  css  js  c++  java
  • 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.
  • 相关阅读:
    18款在线代码片段测试工具
    毫秒必争,前端网页性能最佳实践
    如何判断Javascript对象是否存在
    推荐10款免费的在线UI测试工具
    揭开Socket编程的面纱
    使用 jQuery Ajax 在页面滚动时从服务器加载数据
    对Android开发者有益的40条优化建议
    web api+递归树型结构
    asp.net Lodop实现批量打印
    asp.net lodop单个打印
  • 原文地址:https://www.cnblogs.com/zhuqiwei-blog/p/9553694.html
Copyright © 2011-2022 走看看