zoukankan      html  css  js  c++  java
  • PAT A1132 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 <stdio.h>
     2 #include <string>
     3 #include <iostream>
     4 using namespace std;
     5 int s2n(string s){
     6   int res=0;
     7   for(int i=0;i<s.length();i++){
     8     res = 10*res + s[i]-'0';
     9   }
    10   return res;
    11 }
    12 int main(){
    13   string s;
    14   int n;
    15   scanf("%d",&n);
    16   for(int i=0;i<n;i++){
    17     cin>>s;
    18     int pos=s.length()/2;
    19     string s1,s2;
    20     int n1,n2;
    21     s1=s.substr(0,pos);
    22     s2=s.substr(pos,s.length()-pos);
    23     n1=s2n(s1);
    24     n2=s2n(s2);
    25     if((n1==0 || n2==0) || s2n(s)%(n1*n2)!=0)printf("No
    ");
    26     else printf("Yes
    ");
    27   }
    28 }
    View Code

    注意点:后面两个测试点是其中一半为0的情况,要额外判断。显示浮点错误说明除数遇到了0。

    ---------------- 坚持每天学习一点点
  • 相关阅读:
    团队事后分析
    Gamma阶段发布说明
    Gamma阶段 测试报告
    【Gamma阶段】第十次Scrum Meeting
    【Gamma阶段】第九次Scrum Meeting
    【Gamma阶段】第八次Scrum Meeting
    Gamma展示
    【Gamma阶段】第七次Scrum Meeting
    【Gamma阶段】第六次Scrum Meeting
    【Gamma阶段】第五次Scrum Meeting
  • 原文地址:https://www.cnblogs.com/tccbj/p/10423443.html
Copyright © 2011-2022 走看看