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. ...
随机推荐
- elasticsearch6.7 01.入门指南(1)
Elasticsearch 是一个高度可扩展且开源的全文检索和分析引擎.它可以让您快速.近实时地存储.检索以及分析海量数据.它通常用作那些具有复杂搜索功能和需求的应用的底层引擎或者技术. 下面是 El ...
- 阿里CentOS 7 卸载mysql5.6
查看当前安装mysql情况 rpm -qa|grep -i mysql 执行 yum remove mysql rpm -e mysql-community-release-el7-5.noarch ...
- Vue 系列之 样式相关
Class 与 Style 绑定 动态修改元素样式 <head> <meta charset="utf-8" /> <meta http-equiv= ...
- 读 《CSharp Coding Guidelines》有感
目录 基本原则 类设计指南 属性成员设计指南 其他设计指南 可维护性指南 命名指南 性能指南 框架指南 文档指南 布局指南 相关链接 C# 编程指南 前不久在 Github 上看见了一位大牛创建一个仓 ...
- CSS如何让不相等的字符上下对齐
最后效果: <div class="main"> <span style="font-size:12px;"><dl class= ...
- vue规格新增一对多的例子
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【代码笔记】Web-HTML-头部
代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <!--ti ...
- CSS&JS两种方式实现手风琴式折叠菜单
<div class="accordion"> <div id="one" class="section"> < ...
- Gartner2017年BI研究计划曝光,来看看他研究的都是啥?
文 | 水手哥 本文出自:知乎专栏<帆软数据应用研究院>——数据干货&资讯集中地 近日,Gartner发布了<Analytics and Business Intelli ...
- 自定义ScrollView 实现上拉下拉的回弹效果--并且子控件中有Viewpager的情况
onInterceptTouchEvent就是对子控件中Viewpager的处理:左右滑动应该让viewpager消费 public class MyScrollView extends Scroll ...