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的情况
  • 相关阅读:
    MVC5个人用户账户身份验证集成google和facebook的OAuth2登陆
    2016.8.5
    2016.7.29
    2016.7.25
    如何将返回的JSon字符串用MAP格式读取
    代码里获得系统时间写法
    Mybatis中<![cdata[ ]]>
    Orcal语法Merge into用法
    Page.IsPostBack属性
    Android之打开闪光灯关键代码
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10789686.html
Copyright © 2011-2022 走看看