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. VS 清除编译产生的临时文件、文件夹

    VS编译过程中会产生一些临时文件,通过以下脚本可清除 @echo off for /r %%i in (*.sdf,*.ncb,*.suo,*.exp,*.user,*.aps,*.idb,*.dep ...

  2. IOS -执行时 (消息传递 )

    一 函数调用概述      Objective-C不支持多重继承(同Java和Smalltalk),而C++语言支持多重继承. Objective-C是动态绑定,它的类库比C++要easy操作. Ob ...

  3. vue中的小踩坑(01)

    前言: 昨天算是使用vue2.0+element-ui做了一点小小的页面,可是源于其中遇到的问题,特地整理一下,以防自己还有其他的小伙伴们继续踩坑. 过程:         1.不知道大家有没有注意到 ...

  4. PyQt4开关按钮ToggleButton

    PyQt4没有开关按钮部件.但是我们可以使用在特殊状态下的QPushButton部件来创建开关按钮.而所谓的开关按钮就是一个具有按下和未按下两种状态的普通赶牛.用户可以通过单击按钮来切换其开或者关的状 ...

  5. SpringMvc 400 Bad Request解决方法

    今天做项目的时候突然报出400 Bad Request错误,后台没有出现任何问题. 首先我看了看log日志中没有接受到任何参数,可以确定这个请求并没有发送出去,所以应该是前台数据提交的问题. 然后我看 ...

  6. HTML5文件拖拽上传记录

    JS文件: var FileName = ""; var FileStr = ""; (function () { function $id(id) { ret ...

  7. HTTP/2笔记之消息交换

    前言 无论是HTTP/1.*还是HTTP/2,HTTP的基本语义是不变的,比如方法语义(GET/PUST/PUT/DELETE),状态码(200/404/500等),Range Request,Cac ...

  8. LeetCode - Nth Highest Salary

    题目大概意思是要求找出第n高的Salary,直接写一个Function.作为一个SQL新手我学到了1.SQL中Function的写法和变量的定义,取值.2.limit查询分    页的方法. 在这个题 ...

  9. ios ASIHTTPRequest类库简介和使用说明

    官方网站: http://allseeing-i.com/ASIHTTPRequest/ .可以从上面下载到最新源码,以及获取到相关的资料. 使用iOS SDK中的HTTP网络请求API,相当的复杂, ...

  10. postgresql----排序ORDER BY,分组GROUP BY,分页OFFSET&&LIMIT

    一.GROUP BY 使用GROUP BY分组查询在SELECT子句中只能出现分组字段和聚合函数,HAVING子句相当于WHERE,使用条件过滤数据. 示例1.以a,b分组查询tbl_insert表, ...