PAT 1132 Cut Integer[简单]
1132 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
题目大意:给出一个数n,它的位数是K(输入的一定是偶数),那么将前K/2位与后K/2位分开表示为m和t,判断n/(m*t)之后是不是整数。
//看完这道题就感觉简单极了,但是做了提交之后出现了两个错误
//这个是错误理解:给出一个数n,它的位数是K(输入的一定是偶数),那么将前K/2位与后K/2位分开表示为m和t,判断n/m/t==K/2,不能出现浮点数的情况哦。
//看完这道题就感觉简单极了,但是做了提交之后出现了两个错误
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std; int main() {
int n;
cin>>n;
int x;
for(int i=;i<n;i++){
cin>>x;
int m=x,ct=;
while(m!=){
m/=;
ct++;
}
ct/=;
vector<int> vt;
m=x;
for(int j=;j<ct;j++){
vt.push_back(m%);
m/=;
}
int k=vt[vt.size()-];
for(int j=vt.size()-;j>=;j--){
k=k*+vt[j];
}
if(k==){
cout<<"No"<<'\n';continue;
}
double t=1.0*x/k/m;
if(t==1.0*ct)
cout<<"Yes"<<'\n';
else
cout<<"No"<<'\n';
}
return ;
}/**
1
678900,
这个用例就不行,因为它是/后四舍五入导致的表面上的答案正确。
**/
1.浮点错误,搜索了一下发现是,/0,或者%0.
2.解决了之后,再次提交全部样例是答案错误。
//看完讲解,忽然发现自己理解错题意了,
现在答案正确了:我的AC:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std; int main() {
int n;
cin>>n;
int x;
for(int i=;i<n;i++){
cin>>x;
int m=x,ct=;
while(m!=){
m/=;
ct++;
}
ct/=;
vector<int> vt;
m=x;
for(int j=;j<ct;j++){
vt.push_back(m%);
m/=;
}
int k=vt[vt.size()-];
for(int j=vt.size()-;j>=;j--){
k=k*+vt[j];
}
if(k==){
cout<<"No"<<'\n';continue;
}
//double t=1.0*x/k/m;
if(x%(k*m)==)
cout<<"Yes"<<'\n';
else
cout<<"No"<<'\n';
}
return ;
}/**
1
678900,
这个用例就不行,因为它是/后四舍五入导致的表面上的答案正确。
**/
代码来自:https://www.liuchuo.net/archives/4090
#include <iostream>
using namespace std;
int main() {
int n, num;
scanf("%d", &n);
for (int i = ; i < n; i++) {
scanf("%d", &num);
string s = to_string(num);//直接使用tosting函数,厉害了。
int len = s.length();
int a = stoi(s.substr(, len/));//直接将字符串转换为int 厉害了。
int b = stoi(s.substr(len/));
if (a * b != && num % (a * b) == )
printf("Yes\n");
else
printf("No\n");
}
return ;
}
//真是太简洁了。
1.可以使用so_string函数,直接将int转化为string
2.可以使用stoi直接将string转换为int.
//厉害了。
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 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 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 甲级 1132 Cut Integer
https://pintia.cn/problem-sets/994805342720868352/problems/994805347145859072 Cutting an integer mea ...
- 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 ...
随机推荐
- 设计模式工具:UML基础
类图 矩形框 -类Class 第一层 ...
- mybatis由浅入深day02_7.3二级缓存
7.3 二级缓存 7.3.1 原理 下图是多个sqlSession请求UserMapper的二级缓存图解. 首先开启mybatis的二级缓存. sqlSession1去查询用户id为1的用户信息,查询 ...
- Java集合----Map集合
Map Map 用于保存具有映射关系的数据,因此 Map 集合里保存着两组值,一组值用于保存 Map 里的 Key,另外一组用于保存 Map 里的 Value Map 中的 key 和 value 都 ...
- ios 气泡聊天
最近做的项目里面,有几个模块用到了聊天功能和评论回复的功能,使用的频率还是很高的,所以抽时间做了这个博客,希望能给自己和别人带来方便, 具体代码如下: 1,创建model, #import <F ...
- 【RF库Collections库测试】关键字append to list
Arguments:[ list_ | *values ]Adds `values` to the end of `list`.
- sqlmap tutorial
svn checkout https://svn.sqlmap.org/sqlmap/trunk/sqlmap sqlmap-dev sqlmap.py -u "http://www.isl ...
- linux系统usb挂载
本次例程的环境是在FC6下,通过终端操作的. 注意要挂载U盘需要有管理员的权限. 切换成管理员,输入: su root 然后输入管理员密码,进行密码认证: 成功后,先在 /mnt 下建立一个名叫USB ...
- stm32入门(从51过渡到32)
单片机对于我来说,就是一个超级大机器,上面有一排一排数不尽的开关,我需要做的,就是根据我的设计,拿着一张超级大的表(Datasheet),把需要的开关(reg)都开关(config)到对应功能的位置( ...
- console.log篇
前言: 从接触变成开始,就用到了神奇的“console.log”,原来其中还有很多不为自己知道的“小秘密”,今天就深入研究一下吧 1.可以F12打开控制台,输入console.log(xxx),就可以 ...
- 微信小程序 this.setData 修改json里面的值
page({ data:{ s1:{a:"",b:"b"} }, changeData:function(e){ var cData=this.data.s1; ...