• PAT 1132 Cut Integer


    1132 Cut Integer (20 分)
     

    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 <). 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<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    
    
    ll to_ll(string s){
        ll sum = 0;
        for(int i=0;i < s.size();i++){
            sum = sum*10 + (s[i] - '0');
        }
        return sum;
    }
    
    
    int main(){
    
        int t;
        cin >> t;
        while(t--){
            string s;
            cin >> s;
            string s1 = s.substr(0,s.size()/2);
            string s2 = s.substr(s.size()/2,s.size()/2);
            ll num1 = to_ll(s1);
            ll num2 = to_ll(s2);
            ll num = to_ll(s);
            if(num2 == 0||num1 == 0) {
                printf("No
    ");
                continue;
            }
            if(num%num1 == 0){
                num = num/num1;
                if(num%num2 == 0) printf("Yes
    ");
                else printf("No
    ");
            }
            else printf("No
    ");
        }
    
    
        return 0;
    }

    浮点错误: 您的程序运行时发生浮点错误,比如遇到了除以 0 的情况

       所以发生浮点错误应该考虑程序中:

    • 是否可能出现了一个数除以0的情况
    • 是否可能出现了一个数取余0的情况
    • 是否发生了数据溢出而导致的除以0或者取余0的情况
  • 相关阅读:
    B树/[oracle]connect BY语句
    使用vmware vconverter从物理机迁移系统到虚拟机P2V(多图)
    goldengate常用命令
    GoldenGate 之 Bounded Recovery说明
    RAC环境中threads变更后如何确保goldengate继续正常复制
    简述Oracle IOT(Index Organized Table)
    mybatis-spring最新版下载地址
    12 个 CSS 高级技巧汇总
    Linux命令:useradd
    PHP date()函数详解
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10789686.html
Copyright © 2020-2023  润新知