PAT A1132 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
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int s2n(string s){
int res=;
for(int i=;i<s.length();i++){
res = *res + s[i]-'';
}
return res;
}
int main(){
string s;
int n;
scanf("%d",&n);
for(int i=;i<n;i++){
cin>>s;
int pos=s.length()/;
string s1,s2;
int n1,n2;
s1=s.substr(,pos);
s2=s.substr(pos,s.length()-pos);
n1=s2n(s1);
n2=s2n(s2);
if((n1== || n2==) || s2n(s)%(n1*n2)!=)printf("No\n");
else printf("Yes\n");
}
}
注意点:后面两个测试点是其中一半为0的情况,要额外判断。显示浮点错误说明除数遇到了0。
PAT A1132 Cut Integer (20 分)——数学题的更多相关文章
- 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 1035 Password(20 分)
1035 Password(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the ...
- PAT 甲级 1035 Password (20 分)(简单题)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for ...
- pat 1077 Kuchiguse(20 分) (字典树)
1077 Kuchiguse(20 分) The Japanese language is notorious for its sentence ending particles. Personal ...
- pat 1008 Elevator(20 分)
1008 Elevator(20 分) The highest building in our city has only one elevator. A request list is made u ...
- PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- PAT 1042 Shuffling Machine (20 分)
1042 Shuffling Machine (20 分) Shuffling is a procedure used to randomize a deck of playing cards. ...
随机推荐
- Java学习笔记之——变量与数据类型、运算符
一.变量 1.变量:变化的值 变量在代码运行期间,开辟了一块空间 .这块空间是有地址的,给这块取了个名字, 这个名字就叫做变量名,这块空间放的东西叫做变量值 2.变量的初始化: (1)先声明再赋值: ...
- fast-spring-boot快速开发项目
Introduction fast-spring-boot 集成Spring Boot 2.1,Mybatis,Mybatis Plus,Druid,FastJson,Redis,Rabbit MQ, ...
- Matlab 如何输入矩阵
A=[1 2 3;4 5 6;7 8 9],每行之间用分号隔开 也可以用循环控制输入 n=input('请输入矩阵阶数:') for i=1:n for j=1:n a(i,j ...
- java设计模式-----12、外观模式
Facade模式也叫外观模式,是由GoF提出的23种设计模式中的一种.Facade模式为一组具有类似功能的类群,比如类库,子系统等等,提供一个一致的简单的界面.这个一致的简单的界面被称作facade. ...
- CSS常见布局
一.单列布局 1. 水平居中 1.1 使用inline-block和text-align .parent{text-align:center;} .child{display:inline-block ...
- 虚拟机安装ubuntu18.04及其srs服务器的搭建
第一次写博客,有些地方可能不太完善. 1.安装VMware,我用的是VMware12. 2.下载Ubuntu镜像(自Ubuntu 17.10开始桌面版本不再提供32位安装镜像,Ubuntu Serve ...
- fetch发送Form Data请求并携带cookie
今天我们来说说如何fetch发送Form Data请求并携带cookie,直接进入正题好吧,别问我今天为啥不在开始吹两句了,累到一句牛逼不想吹...... 步骤1: 设置头部,"Conten ...
- loadrunner 场景设计-添加Windows Resources计数器
场景设计-添加Windows Resources计数器 by:授客 QQ:1033553122 目的 监控要测试的windows服务器的资源使用情况 步骤 1.添加视图,方法双击.拖动左侧的Windo ...
- CGI,FastCGI,PHP-FPM,PHP-CLI,modPHP
This might give you a broader understanding of their difference: CGI: (common gateway interface) It ...
- webApi core2 DI通过代码来获取容器里面已注入的对象
请求服务 来自 HttpContext 的一次 ASP.NET 请求中可用的服务通过 RequestServices 集合公开的. 请求服务将你配置的服务和请求描述为应用程序的一部分.当你的对象指定依 ...