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. ...
随机推荐
- PPT文件流转为图片,并压缩成ZIP文件输出到指定目录
实现流程: 接收InputStream流->复制流->InputStream流转为PPT->PPT转为图片->所有图片压缩到一个压缩文件下 注意: 1.PPT文件分为2003和 ...
- 基于python的websocket开发,tomcat日志web页面实时打印监控案例
web socket 接收器:webSocket.py 相关依赖 # pip install bottle gevent gevent-websocket argparse from bottle i ...
- php文件与HTML页面的数据交互
注意:首先需要保证本地配置了php开发环境,如WAMP开发环境 WAMP配置:https://www.cnblogs.com/shiyiaccn/p/9984579.html php获取HTML页面返 ...
- 2018-01-03 烂尾工程: Java实现的汇编语言编译器
在半年前的中文编程的尝试历程小记中简单介绍了这一项目. 由于短期内估计不会继续进行, 而且这个项目好像是至今个人在中文命名实践中的代码量最大的一个项目, 谨在此作一小结. 最新的源码库在program ...
- okhttp 的使用
①在OK HTTP 的GitHub上下载 jar 包 或者添加 grad'le依赖 OK HTTP 的地址 : https://github.com/square/okhttp ②导入jar包不想 ...
- Python实现排列组合
# -*- coding: utf-8 -*-"""Created on Sat Jun 30 11:49:56 2018 @author: zhen"&quo ...
- Python中识别DataFrame中的nan
# 识别python中DataFrame中的nanfor i in pfsj.index: if type(pfsj.loc[i]['WZML']) == float: print('float va ...
- 使用LogPhoneUtil工具类在Android手机保存APP运行日志
最近公司的测试老是提出这样那样的bug,当然也怪自己代码写的烂,所以测试总是会把app搞崩溃,而他们那边崩溃的时候还没有日志打印,自己回来再重现有的时候还真不好复现出来,因此麻烦事就来了.为了方便查看 ...
- 解决Windows10或者其他版本Windows Update报错的问题
最近更新系统,发现报错0x80248014,系统版本为redstone2(创意者更新). 总结发现,只要是windows各个版本自动更新报错的,如0x80开头的一系列错误,都可以通过如下步骤解决: 手 ...
- Spring容器技术内幕之BeanDefinition类介绍
引言 org.springframework.beans.factory.config.BeanDefinition是配置文件< bean >元素标签在容器中地内部表示.< bean ...