zoukankan      html  css  js  c++  java
  • 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 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
     1 #include <map>
     2 #include <set>
     3 #include <queue>
     4 #include <cmath>
     5 #include <stack>
     6 #include <vector>
     7 #include <string>
     8 #include <cstdio>
     9 #include <cstring>
    10 #include <climits>
    11 #include <iostream>
    12 #include <algorithm>
    13 #define wzf ((1 + sqrt(5.0)) / 2.0)
    14 #define INF 0x3f3f3f3f
    15 #define LL long long
    16 using namespace std;
    17 
    18 const int MAXN = 2e3 + 10;
    19 
    20 int t, Z, A, B, len, temp;
    21 
    22 char s[MAXN];
    23 
    24 int my_pow(int x, int n)
    25 {
    26     int ans = 1;
    27     while (n)
    28     {
    29         if (n & 1) ans *= x;
    30         x *= x;
    31         n >>= 1;
    32     }
    33     return ans;
    34 }
    35 
    36 int main()
    37 {
    38     scanf("%d", &t);
    39     while (t --)
    40     {
    41         Z = A = B = 0L;
    42         scanf("%s", &s);
    43 
    44         len = strlen(s), temp = len >> 1;
    45         for (int i = 0, j = len - 1; i < len; ++ i, -- j)
    46             Z += (int)(s[i] - '0') * my_pow(10, j);
    47         for (int i = 0, j = temp - 1; i < temp; ++ i, -- j)
    48             A += (int)(s[i] - '0') * my_pow(10, j);
    49         for (int i = temp, j = temp - 1; i < len; ++ i, -- j)
    50             B += (int)(s[i] - '0') * my_pow(10, j);
    51 
    52         if ((A * B) != 0 && Z % (A * B) == 0) printf("Yes
    ");
    53         else printf("No
    ");
    54     }
    55     return 0;
    56 }
  • 相关阅读:
    《软件工程》团队第一阶段Sprint检查表
    灭霸第一阶段绩效评估
    【Copy攻城狮日志】docker搭建jenkins拉取svn代码打包vue项目部署到nginx
    前端移动App开发环境搭建
    【Copy攻城狮日志】Node快速重命名文件,告别Potplay字幕困扰问题
    centos部署yapi爬坑记
    mint-ui之picker爬坑记
    前端内网穿透,localtunnel你值得拥有!
    Visual Studio Live Share不完全指北
    jq跑马灯效果
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9601946.html
Copyright © 2011-2022 走看看