PAT 甲级 1132 Cut Integer
https://pintia.cn/problem-sets/994805342720868352/problems/994805347145859072
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 <). 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
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
char s[maxn]; void itoa(int x) {
if(x == 0) {
s[0] = '0';
s[1] = 0;
return ;
}
stack<int> st;
while(x) {
st.push(x % 10);
x = x / 10;
}
int sz = 0;
while(!st.empty()) {
s[sz++] = (char)(st.top() + '0');
s[sz] = 0;
st.pop();
}
} int main() {
int T;
scanf("%d", &T);
while(T --) {
int n;
int num1 = 0, num2 = 0;
scanf("%d", &n);
itoa(n);
//printf("%s\n", s);
int len = strlen(s);
for(int i = 0; i < len / 2; i ++)
num1 = (s[i] - '0') + num1 * 10;
for(int i = len / 2; i < len; i ++)
num2 = (s[i] - '0') + num2 * 10; if(num1 * num2 == 0)
printf("No\n");
else {
if(n % (num1 * num2) == 0)
printf("Yes\n");
else
printf("No\n");
}
//printf("%d %d", num1, num2);
}
return 0;
}
PAT 甲级 1132 Cut Integer的更多相关文章
- PAT甲级——A1132 Cut Integer
Cutting an integer means to cut a K digits lone integer Z into two integers of (K/2) digits long int ...
- 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
1132 Cut Integer (20 分) Cutting an integer means to cut a K digits lone integer Z into two integer ...
- PAT 1132 Cut Integer[简单]
1132 Cut Integer(20 分) Cutting an integer means to cut a K digits lone integer Z into two integers o ...
- 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 ...
- 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 ...
- 【PAT甲级】1113 Integer Set Partition (25分)
题意: 输入一个正整数N(2<=N<=1e5),接着输入N个正整数,将这些数字划分为两个不相交的集合,使得他们的元素个数差绝对值最小且元素和差绝对值最大. AAAAAccepted cod ...
- 【PAT甲级】1103 Integer Factorization (30 分)
题意: 输入三个正整数N,K,P(N<=400,K<=N,2<=P<=7),降序输出由K个正整数的P次方和为N的等式,否则输出"Impossible". / ...
随机推荐
- www.pantom.top
新建小站 https://www.pantom.top
- ImageMagick命令执行学习笔记(常见于图片预览处)
实验版本: ImageMagick版本:6.9.2 push graphic-context viewbox 0 0 640 480 fill 'url(https://"|whoami&q ...
- GNU Radio在SDR领域的应用
1 Software Defined Radio 软件无线电(Software Defined Radio,SDR)是一种实现无线通信的新概念和体制.其中以往只能在硬件中实现的组件(例如混频器,滤波器 ...
- Linux入门第二天——基本命令入门(中)
一.文件搜索命令 1.文件搜索命令:locate 速度很快(具体见Linux工具网址的对比),注意无法找到新建的文件(原理暂不展开) locate命令其实是“find -name”的另一种写法,但是要 ...
- Linux入门第一天——基本概述与环境搭建
一.Linux简介 1.历史 Linux内核最初只是由芬兰人李纳斯·托瓦兹(Linus Torvalds)在赫尔辛基大学上学时出于个人爱好而编写的. Linux是一套免费使用和自由传播的类Unix操 ...
- Shrio第二天——认证、授权与其它特性
一.认证——Authentication (即登陆),简单分析之前的HelloWorld的认证: 1. 获取当前的 Subject. 调用 SecurityUtils.getSubject(); 2. ...
- 20155307 2016-2017-2《Java程序设计》课程总结
预备作业1 预备作业1 预备作业1 第1周作业 第2周作业 第3周作业 第4周作业 第5周作业 第6周作业 第7周作业 第8周作业 第9周作业 第10周作业 自认为写得最好一篇博客是?为什么? 是这篇 ...
- 2018.10.17校内模拟赛:T2神光
题面:pdf 首先排序,二分,然后怎么判定是否可行. 最简单的思路是,dp[i][j][k],到第i个,用了j次红光,k次绿光,前i个点都选上了,是否可行.然后转移就行. 然后考试的时候就想到这了,往 ...
- Connect C# to MySQL
Connect C# to MySQL using MySQL Connector/Net, Insert, Update, Select, Delete example, Backup and re ...
- Spring学习(六)-----Spring使用@Autowired注解自动装配
Spring使用@Autowired注解自动装配 在上一篇 Spring学习(三)-----Spring自动装配Beans示例中,它会匹配当前Spring容器任何bean的属性自动装配.在大多数情况下 ...