【PAT甲级】1132 Cut Integer (20分)

题意:

输入一个正整数N(<=20),接着输入N行每行包括一个正整数Z(10<=Z<=2^31),Z的数字位数保证是偶数,把Z从中间一切为二,两个整数的乘积如果是Z的因数,输出Yes,否则输出No。

trick:

当两个数乘积为0时需要特判,否则数据点2和3会出现浮点错误。

AAAAAccepted code:

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 int a[107];
 5 int main(){
 6     ios::sync_with_stdio(false);
 7     cin.tie(NULL);
 8     cout.tie(NULL);
 9     int n;
10     cin>>n;
11     for(int i=1;i<=n;++i){
12         memset(a,0,sizeof(a));
13         long long x;
14         cin>>x;
15         long long temp=x;
16         int cnt=0;
17         while(x){
18             a[++cnt]=x%10;
19             x/=10;
20         }
21         long long y=0,z=0;
22         for(int j=cnt/2;j;--j){
23             y*=10;
24             y+=a[j];
25         }
26         for(int j=cnt;j>cnt/2;--j){
27             z*=10;
28             z+=a[j];
29         }
30         long long xx=y*z;
31         if(xx==0){
32             cout<<"No
";
33             continue;
34         }
35         //cout<<xx<<" "<<y<<" "<<z<<"
";
36         if(temp%xx==0)
37             cout<<"Yes
";
38         else
39             cout<<"No
";
40     }
41     return 0;
42 }
原文地址:https://www.cnblogs.com/ldudxy/p/13151748.html