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 ...
随机推荐
- 2018.2.21 Python 初学习
折腾了一天,一直在用CMD学习Python写Hello World.偶然间发现可以用Pycharm.也算是给后面想学习的人提个醒,方便省事许多. format()使用方法. age = 20name ...
- Unity用Vuforia做AR实现脱卡效果
这篇不错,记录下,博主不让转载 http://blog.csdn.net/qwe161819/article/details/76107105
- UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 166: illegal multibyte sequence
# -*- coding: utf-8 -*-# encoding = utf-8import unittestimport random class TestSequenceFunctions(un ...
- hdu1172(枚举)
中文题,题意就不解释了. 思路:因为答案一定是四位数,所以只要枚举1000-9999,如果符合所有条件,那么保存一下答案,记录一下答案的个数,如果答案是唯一的,那么输出它,否则,就不确定. 代码如下: ...
- 最大熵模型(MEM)
1. 最大熵原理 最大熵Max Entropy原理:学习概率模型时,在所有可能的概率模型(即概率分布)中,熵最大的模型是最好的模型. 通常还有其他已知条件来确定概率模型的集合,因此最大熵原理为:在满足 ...
- java0425 wen IO
- Vue-Router路由 Vue-CLI脚手架和模块化开发 之 使用路由对象获取参数
使用路由对象$route获取参数: 1.params: 参数获取:使用$route.params获取参数: 参数传递: URL传参:例 <route-linke to : "/food ...
- 【MySQL】InnoDB 内存管理机制 --- Buffer Pool
InnoDB Buffer Pool 是一块连续的内存,用来存储访问过的数据页面 innodb_buffer_pool_size 参数用来定义 innodb 的 buffer pool 的大小 是 M ...
- 2019.04.10打卡(HTML)
代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...
- 安装ceph设置镜像源
当安装ceph时 卡在这的时候ceph会替换成自己的镜像源 所以这个时候 赶紧再打开一个终端 替换成国内的清华大学的镜像源 就不会被替换回去了 ceph.repo 文件 [Ceph] name=Ce ...