PAT1132: Cut Integer

Posted 0kk470

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT1132: Cut Integer相关的知识,希望对你有一定的参考价值。

1132. Cut Integer (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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, 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 x 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<=231). 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.首先如果输入的数Z的位数为奇数肯定不满足条件,输出No。
2.如果A乘B为0,肯定不满足条件,输出No
3.剩下情况检查Z % (A*B) 是否为0即可。
代码
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int N;
  while(cin >> N)
  {
      while(N--)
      {
          string num;
          cin >> num;
          int len = num.size();
          if(len % 2 == 1)
          {
              cout << "No" << endl;
              continue;
          }

          string a = num.substr(0,len/2);
          string b = num.substr(len/2,len/2);
          int A = stoi(a),B = stoi(b),Z = stoi(num);
          if(A * B != 0 && Z % (A * B) == 0)
          {
              cout << "Yes" << endl;
          }
          else
              cout << "No" << endl;

      }
  }
}

 

以上是关于PAT1132: Cut Integer的主要内容,如果未能解决你的问题,请参考以下文章

PAT_A1132#Cut Integer

PAT 甲级 1132 Cut Integer

PAT Advanced 1132 Cut Integer (20分)

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

PAT甲级1132 Cut Integer (20分)

1132 Cut Integer (20)