• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
村雨sup
自己选的路,跪着也要走完 XD
博客园    首页    新随笔    联系   管理    订阅  订阅
PAT 1132 Cut Integer
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

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


ll to_ll(string s){
    ll sum = 0;
    for(int i=0;i < s.size();i++){
        sum = sum*10 + (s[i] - '0');
    }
    return sum;
}


int main(){

    int t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        string s1 = s.substr(0,s.size()/2);
        string s2 = s.substr(s.size()/2,s.size()/2);
        ll num1 = to_ll(s1);
        ll num2 = to_ll(s2);
        ll num = to_ll(s);
        if(num2 == 0||num1 == 0) {
            printf("No\n");
            continue;
        }
        if(num%num1 == 0){
            num = num/num1;
            if(num%num2 == 0) printf("Yes\n");
            else printf("No\n");
        }
        else printf("No\n");
    }


    return 0;
}

浮点错误: 您的程序运行时发生浮点错误,比如遇到了除以 0 的情况

   所以发生浮点错误应该考虑程序中:

  • 是否可能出现了一个数除以0的情况
  • 是否可能出现了一个数取余0的情况
  • 是否发生了数据溢出而导致的除以0或者取余0的情况
posted on 2019-04-29 12:19  村雨sup  阅读(115)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3