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 ...
随机推荐
- 改善C#程序的建议5:引用类型赋值为null与加速垃圾回收
http://www.cnblogs.com/luminji/archive/2011/04/07/2007205.html 在标准的Dispose模式中(见前一篇博客“C#中标准Dispose模式的 ...
- 7 -- Spring的基本用法 -- 5... Spring容器中的Bean;容器中Bean的作用域;配置依赖;
7.5 Spring容器中的Bean 7.5.1 Bean的基本定义和Bean别名 <beans.../>元素是Spring配置文件的根元素,该元素可以指定如下属性: default-la ...
- Nginx 链接
Nginx反向代理以及负载均衡配置:http://www.cnblogs.com/Miss-mickey/p/6734831.html
- union和union all的并集(相加)区别
Union因为要进行重复值扫描,所以效率低.如果合并没有刻意要删除重复行,那么就使用Union All 两个要联合的SQL语句 字段个数必须一样,而且字段类型要“相容”(一致): 如果我们需要将两个 ...
- 如果我们的MCU调试不通过,我们该如何测试?(未完待续)
我们拿到一款MCU,首先在选型的时候对他们都会有一个大概的了解,首先我们知道它多大与的FLASH,多大的RAM,是否与我们的项目适合,资源上是否足够,内频是否足够,运行速率能否达到标准,性能怎么样,比 ...
- 【Mysql】 case ... when ... 用法
sql语句查询时给某个空字段赋值 SELECT CASE WHEN field= '' THEN ' WHEN fieldIS NULL THEN ' ELSE field END FROM tabl ...
- linux ctags
在vim 下查找函数的定义是比较方法的事情,尤其是是跨文件的时候. 这时候可以通过安装ctags来实现函数定义跳转. 安装可以直接百度. 安装好之后,首先需要配置vim, 因为一般只有vim打开的文件 ...
- LeetCode——Peeking Iterator
Description: Given an Iterator class interface with methods: next() and hasNext(), design and implem ...
- adb shell dumpsys的用法
一. 打印出设备中所有service的信息 zh@zh:~$adb shell dumpsys -l (字母l)zh@zh:~$adb shell service list 二.查询到运行的syste ...
- mysql如何按周统计数据?
转自:https://www.cnblogs.com/wanghetao/p/3920124.html MySql 按周/月/日统计数据的方法 知识关键词:DATE_FORMAT select DA ...