PAT_A1132#Cut Integer

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:

  • k快乐模拟

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

时间: 2024-11-01 23:20:57

PAT_A1132#Cut Integer的相关文章

pat 1132 Cut Integer(20 分)

1132 Cut Integer(20 分) 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 devid

PAT 甲级 1132 Cut Integer

https://pintia.cn/problem-sets/994805342720868352/problems/994805347145859072 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 an

1132 Cut Integer (20 分)

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

PAT Advanced 1132 Cut Integer (20分)

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

PAT Advanced 1132 Cut Integer (20) [数学问题-简单数学]

题目 Cutting an integer means to cut a K digits long integer Z into two integers of (K/2) digits long integers A and B. For example, afer cutting Z = 167334, we have A = 167 and B = 334. It is interesting to see that Z can be devided by the product of

1132 Cut Integer PAT 甲级真题

#include<iostream> #include<sstream>#include<string>using namespace std;int n;bool judge(string s){ long long t1, t2, t3; stringstream ss; /*ss.clear(); ss << s; ss >> t1; string s1 = s.substr(0,(int) s.size() / 2); ss.clear(

PAT (Advanced Level) 1132~1135:1132 模拟 1133模拟(易超时!) 1134图 1135红黑树

1132 Cut Integer(20 分) 题意:将一个含K(K为偶数)个数字的整数Z割分为A和B两部分,若Z能被A*B整除,则输出Yes,否则输出No. 分析:当A*B为0的时候,不能被Z整除,输出No.否则会出现浮点错误. #include<cstdio> #include<cstring> #include<cstdlib> #include<string> #include<algorithm> #include<map>

A题目

1 1001 A+B Format(20) 2 1002 A+B for Polynomials(25) 3 1003 Emergency(25) 4 1004 Counting Leaves(30) 5 1005 Spell It Right(20) 6 1006 Sign In and Sign Out(25) 7 1007 Maximum Subsequence Sum(25) 8 1008 Elevator(20) 9 1009 Product of Polynomials(25) 10

PAT(甲级)2017年秋季考试

PAT(甲级)2017年秋季考试 还有一题由于上午心情复杂..没调试完.待补. A Cut Integer 模拟题 #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; int getLen(ll x){ int len = 0; while(x){ len++; x/=10; } return len; } int main(){ cin>>n; while(n--){ ll x; ci