题目链接
计蒜客 - 41099
题目
There is a positive integer X, X’s reversion count is Y. For example, X=123, Y=321; X=1234, Y=4321. Z=(X-Y)/9, Judge if Z is made up of only one number(0,1,2…9), like Z=11,Z=111,Z=222,don’t consider '+'and ‘-’.
Input:
Input contains of several test cases. Each test case only contains of a number X, L is the length of X. ( 2 <= L < 100)
Output:
Output “YES”or “NO”.
Sample Input
10
13
Sample Output
YES
YES
题意
给出正整数X,正整数Y是X的翻转数,例如321和123互为翻转数,问(X-Y)/ 9的结果是否只由一个数字组成,例如1,22,333,44444。
思路
数据范围很大(100位),肯定不是硬算,随便写个程序看看什么样的数符合找下规律,很容易发现只有从第二位到倒数第二位对称的数字符合要求。
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int MAXN = 2e5 + 5;
int t, n, m, k, flag = 1;
string s;
int check(int l, int r) {
if(l >= r)return 1;
int mid = (l + r) / 2;
for(int i = l; i <= mid; i++) {
if(s[i] != s[r + l - i])return 0;
}
return 1;
}
int main(void) {
IO;
while(cin >> s) {
int len = s.size();
if(check(1, len - 2)) cout << "YES" << '\n';
else cout << "NO" << '\n';
}
}