PAT_A1132#Cut Integer

博客围绕PAT A1132切割整数问题展开,介绍将K位整数Z切割为两个(K/2)位整数A和B,判断Z能否被A与B的乘积整除。给出输入输出规格、示例,强调模拟解题,同时提醒除法时考虑分母为零情况。

Source:

PAT A1132 Cut Integer (20 分)

Description:

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

Keys:

  • 快乐模拟

Attention:

  • 除法注意考虑分母为零的情况

Code:

 1 /*
 2 Data: 2019-05-24 21:36:30
 3 Problem: PAT_A1132#Cut Integer
 4 AC: 18:02
 5 
 6 题目大意:
 7 根据题意切割整数
 8 输入:
 9 第一行给出,测试数N;
10 接下来N行,给出Z
11 输出:
12 是否能够找到符合条件的A和B,输出Yes or No
13 */
14 
15 #include<cstdio>
16 typedef long long LL;
17 
18 int main()
19 {
20 #ifdef    ONLINE_JUDGE
21 #else
22     freopen("Test.txt", "r", stdin);
23 #endif
24 
25     LL m,n;
26     scanf("%lld", &m);
27     while(m--)
28     {
29         scanf("%lld", &n);
30         LL exp=10,a,b;
31         while(exp*exp<n)
32             exp *= 10;
33         a = n%exp;
34         b = n/exp;
35         if(a!=0 && b!=0 && n%(a*b)==0)
36             printf("Yes\n");
37         else
38             printf("No\n");
39     }
40 
41     return 0;
42 }

 

转载于:https://www.cnblogs.com/blue-lin/p/10920429.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值