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:3167334233312345678Sample 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;}
- 1132. Cut Integer (20)
- 1132. Cut Integer (20)
- 1132. Cut Integer (20)
- 1132. Cut Integer (20)
- 1132. Cut Integer (20)
- PAT甲级 1132. Cut Integer (20)
- PAT 甲级 1132. Cut Integer (20)
- 1132. Cut Integer (20)[数学逻辑]
- 1132. Cut Integer (20)-PAT甲级真题
- cut integer
- PAT 1132 Cut Integer(20)
- PAT甲级1132 Cut Integer (20)
- PAT (Advanced Level) Practise 1132Cut Integer (20)
- PAT-1132 Cut Integer (整数分割)
- cut
- cut
- cut
- cut
- 浅析data、text、bss段
- 找工作之中读老子
- 网格顶点方向的计算(一种新的面积加权方法)
- 把本地文件夹映射成磁盘
- click事件的累加绑定,一次点击,执行多次
- 1132. Cut Integer (20)
- Kotlin学习笔记(1)-类,接口,对象
- URAL 1033|Labyrinth|搜索
- uva 690 Pipeline Scheduling
- Xilinx SDK文本编辑器行号显示和背景颜色改变
- 重装macOS的基本步骤
- 安装MySQL_Python时出现is not a supported wheel on this platform.
- poj 1986 Distance Queries 离线LCA
- string 26线段树