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 <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
- 题解:做了13分钟,满分
- 20分的这一题通常考察的是对string的使用,用到了几个经典的函数,stoi,substr,还有一个to_string没有用到,提醒一下,string可以直接进行比较,a==b,或者a=="PAT"这个样子,a[0],b[1],可以直接访问string的单个位上的字符,这些操作的具体用法在题库中都有得到体现,你需要做题去体会,我这里多讲其实都是空的。。。(其实我也不是很熟练。。。。。也都是向别人学的)
- 我在代码里面标上//debug part的部分,是在我代码编写和调试过程中通过visual studio这个开发环境修改的部分,所以有一个强大的IDE很重要,我觉得能用dev这样的考PAT,应该都是ACM的大神,并不是我们这些水平一般的学生。。。我不是说dev完全不行,凑合凑合也还好。。。我自己就是用dev过来的,但是调试功能的真的差的太多太多了。。。。可能你自己用过会有更深的体会,听我在这里讲你可能觉得无所谓。。。。但是我想提醒你的是,visual studio虽然有很多方便,但是刚开始你首先要把visual studio调整到适合pat编程的模式,这可能有点复杂,你可能要百度试错很多次。。。。如果你的水平和我接近的话。。。从使用门槛的角度,确实dev容易很多
// A1132.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <bits/stdc++.h>//debug part
using namespace std;//debug part
int main()
{
#ifndef ONLINE_JUDGE
FILE* s;
freopen_s(&s, "in.txt", "r", stdin);
#endif // !ONLINE_JUDGE
int n;
cin >> n;//debug part
string z;
for (int i = 0; i < n; i++) {
cin >> z;
int a = stoi(z.substr(0,z.size() / 2));//debug part
int b = stoi(z.substr(z.size() / 2));
if (a * b != 0) {
if (stoi(z) % (a * b) == 0) {
cout << "Yes\n";
}
else {
cout << "No\n";
}
}
else {
cout << "No\n";//debug part
}
}
return 0;
}