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 .
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 <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
AC代码
#include <iostream>
#include <string>
using namespace std;
int main() {
int N;
cin >> N;
while (N--) {
string Num;
cin >> Num;
string A(Num, 0, Num.size() / 2); //得到前半段
string B(Num, Num.size() / 2); //得到后半段
int Ori = 0, TheA = 0, TheB = 0;
for (int i = 0; i < Num.size(); i++) Ori = Ori * 10 + (Num[i] - '0'); //得到原数
for (int i = 0; i < A.size(); i++) TheA = TheA * 10 + (A[i] - '0'); //得到前半段的数
for (int i = 0; i < B.size(); i++) TheB = TheB * 10 + (B[i] - '0'); //得到后半段的数
if (!(TheA*TheB)) { cout << "No" << endl; continue; } //防止浮点错误即取余零的情况
if (!(Ori % (TheA*TheB))) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)