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;
}

  

原文地址:https://www.cnblogs.com/zlrrrr/p/9420583.html

时间: 2024-07-30 05:24:23

PAT 甲级 1132 Cut Integer的相关文章

PAT Advanced 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

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 integers A and B. For example, afer cutting Z = 167334, we have A = 167 and B = 334. It is interesting to see that Z can be devided by the product of

pat 1132 Cut Integer(20 分)

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 devid

1132 Cut Integer PAT 甲级真题

#include<iostream> #include<sstream>#include<string>using namespace std;int n;bool judge(string s){ long long t1, t2, t3; stringstream ss; /*ss.clear(); ss << s; ss >> t1; string s1 = s.substr(0,(int) s.size() / 2); ss.clear(

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

【PAT甲级】1103 Integer Factorization (30分)

1103 Integer Factorization (30分) The K?P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K?P factorization of N for any positive integers N, K an

PAT_A1132#Cut Integer

Source: PAT A1132 Cut Integer (20 分) Description: 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

PAT甲级1005 Spell It Right

题目:PAT甲级 1005 题解:水题.看到题目的第一时间就在想一位一位的mod,最后一加一转换就完事了.结果看到了N最大为10的100的次方,吓得我赶紧放弃这个想法... 发现碰到这种情况用字符串十分好用,这道题应该考察的就是这一点.大致思路就是把数字的每一位放到字符串中,然后通过ASCII码得到每一位的相加结果num,然后把num一位一位的放到stack中,使用stack是因为它先进先出的特性,最后输出就行了. 代码: 1 #include<cstdio> 2 #include<qu

PAT甲级考前整理

终于在考前,刷完PAT甲级130道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种境界.PAT甲级题目总的说卡题目的比较多,卡测试点的比较少,有些题目还会有题意混淆,这点就不吐槽了吧.静下心来耍这130道题,其实磨练的是一种态度与手感,养成的是一种习惯.热爱AC没有错!! 130道题目主要的考点: 1.排序:快速排序,直接插入排序,希尔排序,分治排序,堆排序. 2.图论:拓扑排序.最短路径.深度搜索.广度搜索. 3.树:树的遍历.完全二叉树.AVL. 4.其他:并查集,模拟,哈希.背包.