其他分享
首页 > 其他分享> > PAT 1132 Cut Integer

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\n");
            continue;
        }
        if(num%num1 == 0){
            num = num/num1;
            if(num%num2 == 0) printf("Yes\n");
            else printf("No\n");
        }
        else printf("No\n");
    }


    return 0;
}

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

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

标签:Cut,PAT,string,No,1132,ll,printf,integer,sum
来源: https://www.cnblogs.com/cunyusup/p/10789686.html