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 ...
随机推荐
- [转]在ubuntu下安装sublime text
1添加Sublime-text-3软件包的软件源sudo add-apt-repository ppa:webupd8team/sublime-text-3 2使用以下命令更新系统软件源sudo ap ...
- 对于jsp中编码的理解
1.会话都是从客户端也就是浏览器开始发起的,首先用户将地址输入到地址栏中, 当用户输入enter或者点击转到的按钮时,浏览器会根据当前页面的charset对地址栏中的地址进行encode一次,当服务器 ...
- GIS-ArcGIS 与 ThreeJs交互联动
一.从GIS触发Three场景 MapFeatureLayer.on("click", function (evt) { graphicsLayerOfMouse.clear(); ...
- linux 安装 nodejs
原文地址:https://nodejs.org/en/download/package-manager/#enterprise-linux-and-fedora 1)定位到nodejs的官方源(如果直 ...
- 初学hadoop,windows下安装
先bb一下,woc开始使用Cygwin来模拟linux配置hadoop,然后各种错误,找着找着发现原来2.0+的hadoop可以直接在windows下配置.当时真是1w头神兽飞过. 下载hadoop ...
- ExtJS 6.2 基础使用
一. 安装: 下载两个压缩包:分别是 ext-6.2.0-gpl(这个是ExtJS 的SDK文件,创建新项目的时候需要用). SenchaCmd-6.5.2-windows-64bit (这个下载下来 ...
- Docker源码分析(七):Docker Container网络 (上)
1.前言(什么是Docker Container) 如今,Docker技术大行其道,大家在尝试以及玩转Docker的同时,肯定离不开一个概念,那就是“容器”或者“Docker Container”.那 ...
- flash 逐字,逐行歌词实现,添加伪3D效果
项目结构: 效果如图: 项目为公司项目,下载人员禁止用于商业项目中. 项目开发工具:FlashDevelop 点击下载
- List<String>和String相互转换
List<String>转String String Message=""; for (String msg : message) { Message = Messag ...
- 有关velocity的资料(等待整理)
proxy-target-class="true" 与proxy-target-class="false"的区别: proxy-target-class属性值决 ...