本文主要是介绍(甲)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
题意:
给你一个数字N,下面跟着N个数字Z(Z的位数为偶数),让你把数字从中间分成两个数字A和B,如果 Z%(A*B)==0,就输出Yes,否则输出No;
注意:当A*B==0时,就输出No,不能直接取余,会发生浮点错误。
代码如下:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;int n;
char a[1010];
int x,y,s;int main()
{scanf("%d",&n);while(n--){scanf("%s",&a);int l=strlen(a);x=y=s=0;for(int i=0; i<(l/2); i++){x=x*10+a[i]-'0';s=s*10+a[i]-'0';}for(int i=l/2; i<l; i++){y=y*10+a[i]-'0';s=s*10+a[i]-'0';}if(x*y!=0)//注意,当X*Y==0时,计算s%(x*y)会发生浮点错误;{if(s%(x*y)==0)printf("Yes\n");elseprintf("No\n");}elseprintf("No\n");}return 0;
}
这篇关于(甲)1132 Cut Integer (20 分)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!