zoukankan      html  css  js  c++  java
  • 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 <). 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

    题解:
    string的使用
    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=1010;
    int main(){
        string z;
        string a,b;
        int n;
        cin>>n;
        while(n--){
            cin>>z;
            int len=z.length();
            a=z.substr(0,len/2);
            b=z.substr(len/2,len);
            int num1=0,num2=0,num=0;
            for(int i=0;i<z.length();i++){
                num=num*10+(z[i]-'0');
            }
            for(int i=0;i<a.length();i++){
                num1=num1*10+(a[i]-'0');
                num2=num2*10+(b[i]-'0');
            }
            int m;
            if(num1*num2==0){
                cout<<"No"<<endl;
                continue;
            }
            m=num/(num1*num2);
            if(m*num1*num2==num){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
            }
        
        return 0;
    }
  • 相关阅读:
    性能战术
    易用性
    可操作性
    软件架构师如何工作
    idea安装
    Windows下安装TensorFlow
    进度十四(11.01)
    进度十三(10.31)
    进度十二(10.30)
    进度十一(10.29)
  • 原文地址:https://www.cnblogs.com/dreamzj/p/14410008.html
Copyright © 2011-2022 走看看