PAT甲级1132Cut Integer

题目链接

https://pintia.cn/problem-sets/994805342720868352/problems/994805347145859072

题解

给n个k位(k为偶数)的整数z,将其分成a和b,判断z/(a*b)是不是一个整数即可

这里要注意a和b是否为0,这是个边界情况,如果没有处理这个边界情况,有2个测试点不能过,只能得14分

// Problem: PAT Advanced 1132
// URL: https://pintia.cn/problem-sets/994805342720868352/problems/994805347145859072
// Tags: Math

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int n;
    cin >> n;
    while (n--){
        string z;
        cin >> z;
        string a = z.substr(0, z.length() / 2), b = z.substr(z.length() / 2, z.length() / 2);
        int mul = stoi(a) * stoi(b);
        if (mul != 0 && stoi(z) % mul == 0){
            cout << "Yes
";
        }
        else{
            cout << "No
";
        }
    }
    return 0;
}

作者:@臭咸鱼

转载请注明出处:https://www.cnblogs.com/chouxianyu/

欢迎讨论和交流!


原文地址:https://www.cnblogs.com/chouxianyu/p/13448017.html