zoukankan      html  css  js  c++  java
  • 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的情况
  • 相关阅读:
    团队选题报告
    第二次结对作业
    高级软件工程团队第一次作业
    第一次结队作业
    高级软件工程第二次作业
    高级软件工程第一次作业
    洛谷 题解 2165 [AHOI2009]飞行棋
    洛谷 题解 P1684 考验
    洛谷 题解 P4613 【[COCI2017-2018#5] Olivander】
    洛谷 题解 P5534 【【XR-3】等差数列】
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10789686.html
Copyright © 2011-2022 走看看