PAT1132 Cut Integer (20分)

原文鏈接:我的個人博客

原題鏈接

  PAT1132 Cut Integer (20分)

考點

  字符串處理,字符串數字轉換

思路

  將一個整數Z,切分成長度爲len/2的兩個部分A和B。再判斷Z是否能整除A*B

代碼

#include <bits/stdc++.h>
using namespace std;
 
int sti(string s){
    int ans;
    stringstream ss;
    ss<<s;
    ss>>ans;
    return ans;
} 
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        int len = s.length();
        string a = s.substr(0,len/2);
        string b = s.substr(len/2);
        int Z = sti(s);
        int A = sti(a);
        int B = sti(b);
        if(A*B==0){
            cout<<"No"<<endl;
        }else{
            if(Z%(A*B)==0){
                cout<<"Yes"<<endl;
            }else{
                cout<<"No"<<endl;
            }           
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章