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 ...
随机推荐
- 024-PHP常用字符串函数(一)
<?php $first = "abc"; $second = "aBc"; )//字串比较 { print("字符串相等:".&qu ...
- Spring配置数据源的三种方法
前言:今天接触新项目发现用的是JNDI配置数据源,用度娘倒腾了一会也没弄好,只好用平常用的方法,结果发现BasicDataSource和DriverManagerDataSource也是不同的,所以记 ...
- 吴裕雄--天生自然C++语言学习笔记:C++ STL 教程
C++ STL(标准模板库)是一套功能强大的 C++ 模板类,提供了通用的模板类和函数,这些模板类和函数可以实现多种流行和常用的算法和数据结构,如向量.链表.队列.栈. C++ 标准模板库的核心包括以 ...
- Elasticsearch 使用集群 - 创建和查询文档
章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...
- POJ 1584:A Round Peg in a Ground Hole
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5741 Acc ...
- java初学小项目-酒店客房管理系统
最近初次接触JAVA,感觉之前学的C语言很有用,跟着视频做了一个小项目-酒店客房管理系统 /* 酒店客房管理系统 */ import java.util.Scanner;//通过键盘来输入命令需要的引 ...
- WordPress站点绑定多个域名
refer to https://blog.csdn.net/wzl505/article/details/54970321 打开根目录下的 wp-config.php 文件,找到 require_o ...
- PAT A1018
A 1018 Public Bike Management 这个题目算是比较典型的一个.我分别用dfs,及dijkstra+dfs实现了一下. dfs实现代码: #include <cstdio ...
- [ACTF2020 新生赛]Include
0x00 知识点 本地文件包含 ?file=php://filter/read/convert.base64-encode/resource=index.php ?file=php://filter/ ...
- POJ 1562:Oil Deposits
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14462 Accepted: 7875 Des ...