zoukankan      html  css  js  c++  java
  • PAT甲级——A1132 Cut Integer

    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

     1 #include <iostream>
     2 #include <string>
     3 using namespace std;
     4 int main()
     5 {
     6     int n, num, a, b;
     7     cin >> n;
     8     while (n--)
     9     {
    10         string str, str1, str2;
    11         cin >> str;
    12         str1.assign(str.begin(), str.begin() + str.length() / 2);
    13         str2.assign(str.begin() + str.length() / 2, str.end());
    14         num = atoi(str.c_str());
    15         a = atoi(str1.c_str());
    16         b = atoi(str2.c_str());
    17         if ((a*b) > 0 && num % (a*b) == 0)
    18             cout << "Yes" << endl;
    19         else
    20             cout << "No" << endl;
    21     }
    22     return 0;
    23     
    24 }


  • 相关阅读:
    用WebStorm运行Vue项目
    秋招圆满结束
    最新的秋招进度 10月21号
    来更新一下秋招的进度~
    华为三面完进池子啦~9月17日
    C++ 迭代器失效问题
    C++类相关问题(空类、多态、重载、继承)
    C++各种变量、类型的存储位置
    写一个面试中场景题的总结
    明天要面阿里HR面了
  • 原文地址:https://www.cnblogs.com/zzw1024/p/11488215.html
Copyright © 2011-2022 走看看