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 <2​31​​). 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[简单]的更多相关文章

  1. PAT 1132 Cut Integer

    1132 Cut Integer (20 分)   Cutting an integer means to cut a K digits lone integer Z into two integer ...

  2. 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 ...

  3. 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 ...

  4. PAT 甲级 1132 Cut Integer

    https://pintia.cn/problem-sets/994805342720868352/problems/994805347145859072 Cutting an integer mea ...

  5. 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 ...

  6. 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 ...

  7. 1132 Cut Integer

    题意:略. 思路:注意除数可能为0的情况,不然会导致浮点错误. 代码: #include <iostream> #include <string> using namespac ...

  8. PAT1132: Cut Integer

    1132. Cut Integer (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Cutting a ...

  9. PAT_A1132#Cut Integer

    Source: PAT A1132 Cut Integer (20 分) Description: Cutting an integer means to cut a K digits lone in ...

随机推荐

  1. Extjs学习笔记--(三,调试技巧)

    FireFox 1.firedebug(略) 2.illuminations 在illuminations页面可也看到缩写的extjs的代码,同时可以进行相应的调试 3,Firedebug AutoC ...

  2. swift - 利用UIDatePicker实现定时器的效果

    效果图如下: 可以通过UIDatePicker调整倒计时的时间,然后点击UIButton开始倒计时,使用NSTimer进行倒计时的时间展示,我是声明了一个label也进行了标记, 然后点击按钮开始倒计 ...

  3. MySQL开启预编译环境

    Mysql是默认 没有开启预编译的,需要在配置中加上 jdbc:mysql://xxx.22.11.31:3306/dbname?useServerPrepStmts=true

  4. Python 数据类型:字符串

    一.字符串介绍 字符串是由单引号/双引号/三引号引起来的,由字母 .数字或符号等构成的一串字符 In [1]: name = "Tom" # 定义字符串 In [2]: type( ...

  5. java基础---->java中字符编码问题(一)

    这里面对java中的字符编码做一个总结,毕竟在项目中会经常遇到这个问题.爱不爱都可以,我怎样都依你,连借口我都帮你寻. 文件的编码格式 一.关于中文的二进制字节问题 public static Str ...

  6. LeetCode——Implement Stack using Queues

    Description: Implement the following operations of a stack using queues. push(x) -- Push element x o ...

  7. Python的反序列化漏洞

    最近准备研究一下反序列化漏洞,但是Java代码看不懂,所以先找一个python的看起,毕竟这种漏洞在python.php中一样存在,等研究明白了基本原理后去看java的反序列化漏洞. python反序 ...

  8. Egret打包App 短暂黑屏解决方案 (Egret4.1.0)

    论坛已经有人解决:http://bbs.egret.com/forum.php?mod=viewthread&tid=30288&highlight=app%2B%E9%BB%91%E ...

  9. c# 给button添加不规则的图片以及用pictureBox替代button响应点击事件

    1.Flat button 用这个方法,前提是要把button的type设置为Flat button1.TabStop = false;button1.FlatAppearance.BorderSiz ...

  10. linux 下 安装go

    首先肯定是下载资源包了,链接汇总在http://www.golangtc.com/download,我用的是 http://www.golangtc.com/static/go/go1.4beta1. ...