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 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 <2?31??). 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
 1 #include <map>
 2 #include <set>
 3 #include <queue>
 4 #include <cmath>
 5 #include <stack>
 6 #include <vector>
 7 #include <string>
 8 #include <cstdio>
 9 #include <cstring>
10 #include <climits>
11 #include <iostream>
12 #include <algorithm>
13 #define wzf ((1 + sqrt(5.0)) / 2.0)
14 #define INF 0x3f3f3f3f
15 #define LL long long
16 using namespace std;
17
18 const int MAXN = 2e3 + 10;
19
20 int t, Z, A, B, len, temp;
21
22 char s[MAXN];
23
24 int my_pow(int x, int n)
25 {
26     int ans = 1;
27     while (n)
28     {
29         if (n & 1) ans *= x;
30         x *= x;
31         n >>= 1;
32     }
33     return ans;
34 }
35
36 int main()
37 {
38     scanf("%d", &t);
39     while (t --)
40     {
41         Z = A = B = 0L;
42         scanf("%s", &s);
43
44         len = strlen(s), temp = len >> 1;
45         for (int i = 0, j = len - 1; i < len; ++ i, -- j)
46             Z += (int)(s[i] - ‘0‘) * my_pow(10, j);
47         for (int i = 0, j = temp - 1; i < temp; ++ i, -- j)
48             A += (int)(s[i] - ‘0‘) * my_pow(10, j);
49         for (int i = temp, j = temp - 1; i < len; ++ i, -- j)
50             B += (int)(s[i] - ‘0‘) * my_pow(10, j);
51
52         if ((A * B) != 0 && Z % (A * B) == 0) printf("Yes\n");
53         else printf("No\n");
54     }
55     return 0;
56 }

原文地址:https://www.cnblogs.com/GetcharZp/p/9601946.html

时间: 2024-11-07 13:01:50

pat 1132 Cut Integer(20 分)的相关文章

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

pat 1035 Password(20 分)

1035 Password(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) fro

pat 1077 Kuchiguse(20 分) (字典树)

1077 Kuchiguse(20 分) The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a preference is called "Kuchiguse" and is often

[PTA] PAT(A) 1008 Elevator (20 分)

目录 Problem Description Input Output Sample Sample Input Sample Output Solution Analysis Code Problem portal: 1008 Elevator (20 分) Description  The highest building in our city has only one elevator. A request list is made up with $N$ positive numbers

PAT乙级1088-----三人行 (20分)

1088 三人行 (20分) 输入样例 1: 48 3 7 输出样例 1: 48 Ping Cong Gai 输入样例 2: 48 11 6 输出样例 2: No Solution 思路:1.丙的能力值有可能是小数因此要用double 首次通过代码: 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 5 6 7 int main(){ 8 int m,x,y; 9 int flag=1; 10 s

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 甲级 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 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(