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.
  • 相关阅读:
    vue 之循环添加不同class
    小程序 之使用HMACSHA1算法加密报文
    微信小程序 之wx.getLocation()获取地理信息中的小坑
    js 时间戳与yyyy-mm-dd或yyyy-MM-dd HH-mm-ss互相转换
    小程序 之登录 wx.login()
    打开串口(COM)号大于9时报错
    linux的mysql权限错误导致看不到mysql数据库
    Nginx报错汇总
    获取磁盘总空间和剩余空间
    关于CoCreateInstance的0x800401f0问题
  • 原文地址:https://www.cnblogs.com/zhuqiwei-blog/p/9553694.html
Copyright © 2011-2022 走看看