1. 程式人生 > 實用技巧 >PAT甲級1132Cut Integer

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\n";
        }
        else{
            cout << "No\n";
        }
    }
    return 0;
}

作者:@臭鹹魚

轉載請註明出處:https://www.cnblogs.com/chouxianyu/

歡迎討論和交流!