zoukankan      html  css  js  c++  java
  • PAT1132: Cut Integer

    1132. Cut Integer (20)

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    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, 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 x 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.首先如果输入的数Z的位数为奇数肯定不满足条件,输出No。
    2.如果A乘B为0,肯定不满足条件,输出No
    3.剩下情况检查Z % (A*B) 是否为0即可。
    代码
    #include<iostream>
    #include<string>
    using namespace std;
    int main()
    {
      int N;
      while(cin >> N)
      {
          while(N--)
          {
              string num;
              cin >> num;
              int len = num.size();
              if(len % 2 == 1)
              {
                  cout << "No" << endl;
                  continue;
              }
    
              string a = num.substr(0,len/2);
              string b = num.substr(len/2,len/2);
              int A = stoi(a),B = stoi(b),Z = stoi(num);
              if(A * B != 0 && Z % (A * B) == 0)
              {
                  cout << "Yes" << endl;
              }
              else
                  cout << "No" << endl;
    
          }
      }
    }
  • 相关阅读:
    学习日志---4.5.6
    学习日志---3
    学习日志---2
    学习日志---1
    阅读《大型网站技术架构:核心原理与案例分析》第五、六、七章
    淘宝网的质量属性的六个常见属性场景
    虚继承 private virtual class
    C++ 类中什么时候需要一个operator<
    C++ 中关于 输出的重定向
    C++ 元编程 学习二
  • 原文地址:https://www.cnblogs.com/0kk470/p/7635057.html
Copyright © 2011-2022 走看看