title: PAT1132
date: 2021-01-22 20:03:07
tags: PAT
1132
题目:
字符串能不能被分割后的两个字串乘积整除
范围:
- 20个样例
- 每个样例
10 <= x < 2^31
分析:
- be devided by 除以,被整除
- 从中间分割无论如何不会超
int
范围
解法:
正常解就好,有一个坑,可能分出来有0,不能除零直接输出 No
代码:
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std ;
int main(){
int n;
cin>>n;
char a[20][20];
for(int i = 0; i < n; i++){
scanf("%s", a[i]);
}
for(int i = 0; i < n; i++){
// cout<<i<<endl;
char * tmp = a[i];
// scanf("%s", tmp);
int len = strlen(tmp);
long x, y, z, v;
sscanf(tmp, "%d", &x);
y = x;
v = x;
z = 1;
for(int j = 0; j < len/2; j++){
y = y / 10;
z = z * 10;
}
x = x - y * z;
// cout<<v<<" "<<x<<" "<<y<<" "<<x * y<<endl;
if(x == 0 || y == 0) cout<<"No"<<endl;
else if(v % ( x * y ) == 0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
/*
3
167334
2333
12345678
*/