PAT 1132 Cut Integer
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 <). 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<bits/stdc++.h>
using namespace std;
typedef long long ll; ll to_ll(string s){
ll sum = ;
for(int i=;i < s.size();i++){
sum = sum* + (s[i] - '');
}
return sum;
} int main(){ int t;
cin >> t;
while(t--){
string s;
cin >> s;
string s1 = s.substr(,s.size()/);
string s2 = s.substr(s.size()/,s.size()/);
ll num1 = to_ll(s1);
ll num2 = to_ll(s2);
ll num = to_ll(s);
if(num2 == ||num1 == ) {
printf("No\n");
continue;
}
if(num%num1 == ){
num = num/num1;
if(num%num2 == ) printf("Yes\n");
else printf("No\n");
}
else printf("No\n");
} return ;
}
浮点错误: 您的程序运行时发生浮点错误,比如遇到了除以 0 的情况
所以发生浮点错误应该考虑程序中:
- 是否可能出现了一个数除以0的情况
- 是否可能出现了一个数取余0的情况
- 是否发生了数据溢出而导致的除以0或者取余0的情况
PAT 1132 Cut Integer的更多相关文章
- 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 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
https://pintia.cn/problem-sets/994805342720868352/problems/994805347145859072 Cutting an integer mea ...
- 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 ...
- 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 int ...
- 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 ...
- 1132 Cut Integer
题意:略. 思路:注意除数可能为0的情况,不然会导致浮点错误. 代码: #include <iostream> #include <string> using namespac ...
- PAT1132: Cut Integer
1132. Cut Integer (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Cutting a ...
- PAT_A1132#Cut Integer
Source: PAT A1132 Cut Integer (20 分) Description: Cutting an integer means to cut a K digits lone in ...
随机推荐
- 语音活性检测器py-webrtcvad安装使用
谷歌为WebRTC项目开发的VAD是目前最优秀.最先进和免费的产品之一.webrtcvad是WebRTC语音活动检测器(VAD)的python接口.兼容python2和python3.功能是将一段音频 ...
- Linux替换文件内容sed命令
sed -e 4a\newline testfile //在第四行后添加一行,并将结果输出到标准输出.-e,以指定脚本处理文本文件:a,新增. nl /etc/passwd | sed '2,5d' ...
- Linux基础命令---sar显示系统活动信息
sar sar指令用来收集.报告.保存系统的活动信息.sar命令将操作系统中选定的累积活动计数器的内容写入标准输出.会计系统根据参数“interval”.“count”中的值,写入以秒为单位的指定间隔 ...
- phpcms公共函数库 总结
* global.func.php 公共函数库 /** * 返回经addslashes处理过的字符串或数组 * @param $string 需要处理的字符串或数组 * @return mixed ...
- 关于React Native中FlatList的onEndReached属性频繁调用的一种解决办法
FlatList组件是RN0.43后引入的组件.作为高性能列表组件,FlatList在ListView的基础上优化了加载性能并简化了渲染过程.不仅如此,该组件还提供了onRefresh和onEndRe ...
- python各种转义字符
- workbench使用小笔记(不定期持续更新)
1. 删除不使用的工作空间 在使用workbench时,之前可能建了好几个工作空间,现在有一些不使用了,每次打开都能还能看到它们,对于强迫症来说多少有一些不爽.如下图: 现在,就把那些不使用的工作空间 ...
- 标签EL和JSTL解读
1. EL标签:出现代替输出:<%=%> EL输出格式(特点:只能输出,不带逻辑) ${key值} 查找顺序:page,request,session,application **在不加 ...
- phtyon
https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014316399410395 ...
- 主成分分析 SPSS、python实例分析
今天,在西瓜书上看到了主成分分析法,之前建模有接触过但是理解不够深刻,今天再次和这一位老朋友聊聊. 主成分分析(Principal Component Analysis,PCA), 是一种统计方法.通 ...