PAT1132: Cut Integer
1132. Cut Integer (20)
時間限制 400 ms 內存限制 65536 kB 代碼長度限制 16000 B 判題程序 Standard 作者 CHEN, YueCutting an integer means to cut a K digits long 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 x 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思路
水題
1.首先如果輸入的數Z的位數為奇數肯定不滿足條件,輸出No。
2.如果A乘B為0,肯定不滿足條件,輸出No
3.剩下情況檢查Z % (A*B) 是否為0即可。
代碼 #include<iostream> #include<string> using namespace std; int main() {int N;while(cin >> N){while(N--){string num;cin >> num;int len = num.size();if(len % 2 == 1){cout << "No" << endl;continue;}string a = num.substr(0,len/2);string b = num.substr(len/2,len/2);int A = stoi(a),B = stoi(b),Z = stoi(num);if(A * B != 0 && Z % (A * B) == 0){cout << "Yes" << endl;}elsecout << "No" << endl;}} }
?
轉載于:https://www.cnblogs.com/0kk470/p/7635057.html
總結
以上是生活随笔為你收集整理的PAT1132: Cut Integer的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [BZOJ 5072]小A的树
- 下一篇: python 全栈开发,Day36(作业