1132. Cut Integer (20)

来源:互联网 发布:中断windows更新 编辑:程序博客网 时间:2024/06/06 01:41

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, 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:
3167334233312345678
Sample Output:
YesNoNo

注意点:

1.输入的整数以左边第一个非0的数字为开头,计算整数的长度。

2.防止乘法结果溢出,保险起见使用long long类型定义整数变量。


我的代码:

#include<iostream>#include<sstream>using namespace std;long long digit(long long n){long long k=0;while(n>0){n=n/10;k++;}return k;}int main(){long long n,i,m1,m2;cin>>n;while(n--){cin>>m1;m2=m1;long long x=digit(m1),y=0,z=0;char a[60];stringstream ss;ss<<m1;ss>>a;for(i=0;i<x/2;i++)y=y*10+(a[i]-'0');for(i=x/2;i<x;i++)z=z*10+(a[i]-'0');if(y*z!=0){if(m2%(y*z)==0) puts("Yes");else puts("No");}else puts("No");}return 0;}