PAT Advanced 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, afer 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
题目分析
已知偶数K位正整数N,从中间分为两部分其长度相等的A,B两数,若N能被(A+B)整除,就满足条件,输出Yes,否则输出No
解题思路
- 字符串截取左右部分
- N%(A+B)==0 -- Yes
易错点
- A*B有可能为0,如:N=10
Code
#include <iostream>
#include <string>
using namespace std;
int main(int argc,char * argv[]) {
int n,z;
scanf("%d",&n);
for(int i=0; i<n; i++) {
scanf("%d",&z);
string s= to_string(z);
int l = stoi(s.substr(0,s.length()/2));
int r = stoi(s.substr(s.length()/2,s.length()/2));
if(l*r!=0&&z%(l*r)==0) //l*r可能为0,比如10,测试点2,3
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
PAT Advanced 1132 Cut Integer (20) [数学问题-简单数学]的更多相关文章
- PAT 甲级 1132 Cut Integer
https://pintia.cn/problem-sets/994805342720868352/problems/994805347145859072 Cutting an integer mea ...
- 1132. Cut Integer (20)
Cutting an integer means to cut a K digits long integer Z into two integers of (K/2) digits long int ...
- PAT 1132 Cut Integer
1132 Cut Integer (20 分) Cutting an integer means to cut a K digits lone integer Z into two integer ...
- pat 1132 Cut Integer(20 分)
1132 Cut Integer(20 分) Cutting an integer means to cut a K digits lone integer Z into two integers o ...
- PAT 1132 Cut Integer[简单]
1132 Cut Integer(20 分) Cutting an integer means to cut a K digits lone integer Z into two integers o ...
- PAT Advanced 1096 Consecutive Factors (20) [数学问题-因子分解 逻辑题]
题目 Among all the factors of a positive integer N, there may exist several consecutive numbers. For e ...
- PAT Advanced 1088 Rational Arithmetic (20) [数学问题-分数的四则运算]
题目 For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate ...
- PAT Advanced 1081 Rational Sum (20) [数学问题-分数的四则运算]
题目 Given N rational numbers in the form "numerator/denominator", you are supposed to calcu ...
- PAT Advanced 1069 The Black Hole of Numbers (20) [数学问题-简单数学]
题目 For any 4-digit integer except the ones with all the digits being the same, if we sort the digits ...
随机推荐
- Inheritance and the prototype chain 继承和 原型 链
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain Inherita ...
- c++程序—switch分支
#include<iostream> using namespace std; #include<string> int main() { //多元分支 cout <&l ...
- UVA - 11582 Colossal Fibonacci Numbers! (巨大的斐波那契数!)
题意:输入两个非负整数a.b和正整数n(0<=a,b<264,1<=n<=1000),你的任务是计算f(ab)除以n的余数,f(0) = 0, f(1) = 1,且对于所有非负 ...
- Windows系统自带选择文件的对话重写和居中处理
class CMyFileDialog: public CFileDialogImpl<CMyFileDialog> { public: CMyFileDialog(BOOL bOpenF ...
- 洛谷 P2370 yyy2015c01的U盘
题目传送门 解题思路: 先将每个文件按照占空间从小到大排序,然后跑背包,当到了某一个文件时,价值够了,那么当前文件的体积就是答案. 其实本题是可以二分答案的,但是写挂了... AC代码: #inclu ...
- PHP二维数组--去除指定列含有重复项的数组
给定二维数组: $arr = array( '0' => array('张三',2,3,4), '1' => array('李四',2,3,4), '2' => array('张三' ...
- C++ STD Gems03
transform.for_each #include <iostream> #include <vector> #include <string> #includ ...
- 字符,字符串,int之间互相转换
字符转换成字符串:String str = String.valueOf(ch); 字符转换成int: int a = ch; 字符串转换成字符:char ch = str.charAt(0); 字符 ...
- MongoDB四-操作索引
转自: http://www.cnblogs.com/huangxincheng/archive/2012/02/29/2372699.html 我们首先插入10w数据,上图说话: 一:性能分析函数( ...
- 关于win10 使用eclipse如何配置环境变量
关于环境变量的配置,在百度上有很多教程,但对于我来说完成这步操作确实不简单,所以决定在这里分享一下配置方法. 1.安装好jdk/jre. 官网都有安装文件,仔细一些,就能安装成功,可以自定义安装路径 ...