美文网首页
PAT 甲级 刷题日记|A 1132 Cut Integer (

PAT 甲级 刷题日记|A 1132 Cut Integer (

作者: 九除以三还是三哦 | 来源:发表于2021-09-06 08:58 被阅读0次

思路

这道题是将K位数切分为两个k/2位数字,需要考虑到特殊情况, 如3500这样的数,防止浮点错误。

代码

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin>>n;
    for (int i = 0; i < n; i++) {
        string num;
        cin>>num;
        int len = num.size() / 2;
        string n1 = num.substr(0, len);
        string n2 = num.substr(len);
        int r = stoi(num);
        int r1 = stoi(n1);
        int r2 = stoi(n2);
        if (r2 != 0 && r % (r1 * r2) == 0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
} 

相关文章

网友评论

      本文标题:PAT 甲级 刷题日记|A 1132 Cut Integer (

      本文链接:https://www.haomeiwen.com/subject/woiyiltx.html