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. ...
随机推荐
- csharp: Configuring ASP.NET with Spring.NET and FluentNHibernate
Domain: FluentNhibernateLocalSessionFactoryObject.cs using System; using System.Collections.Generic; ...
- 【代码笔记】Web-JavaScript-JavaScript用法
一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- 【读书笔记】iOS-基带攻击
一,iOS设备中的蜂窝网络通信栈运行在专门的芯片上,这个芯片就是数字基带处理器. 参考资料:<黑客攻防技术宝典-iOS实战篇>
- python之继承
1.经典MRO : 树形结构的深度遍历优先 - > 树形结构遍历 class A: pass class B(A): pass class C(A): pass class D(B, C): p ...
- Linux常用系统命令
致歉:各位看到此博客的朋友们 因为命令的数量挺多的很多命令也都很简单 我就总结了一下具体的命令和这个命令是做什么的,主要的使用方法是链接到http://man.linuxde.net/的网站的,请各 ...
- 《Inside C#》笔记(十三) 多线程 下
一 任务调度 当一个线程的时间片被用尽后,处理器会切换到另一个线程,但关于如何确定执行哪一个线程呢,这就涉及到了线程或任务的优先级. a) 每个线程都有优先级,任务调度算法会根据各线程的不同优先级来决 ...
- Android根据图片Uri获取图片path绝对路径的几种方法【转】
在Android 编程中经常会用到Uri转化为文件路径,如我们从相册选择图片上传至服务器,一般上传前需要对图片进行压缩,这时候就要用到图片的绝对路径. 下面对我开发中uri转path路径遇到的问题进行 ...
- il8n国际化
il8n国际化 支持多国语言的web应用,根据客户端系统的语言类型返回对应的界面 方案 为每种语言提供一套相应的资源文件,并以规范化命名的方式保存在特定的目录中,由系统自动根据客户端语言选择适合的资源 ...
- mybatis学习系列一(mybatis简介/使用)
1mybatis简介(1) 1.1工具:jbbc,jdbctemplate 功能简单,sql语句编写在java代码里面,硬编码高耦合的方式 1.2 框架:整体解决方案 1.2.1 Hibernate: ...
- Scrapy爬虫入门
1.安装Scrapy 打开Anaconda Prompt,执行:pip install Scrapy执行安装! 注意:要是安装过程中抛出: error: Microsoft Visual C++ 14 ...