计蒜客——Reversion Count

  • Reversion Count
  • 解析:题目数字的长度最大为 99,因此使用字符串处理,那么必然这些数存在某些规律。对于数 a (XYZW) 和数 b (WZYX),原式 = (1000X + 100Y + 10Z +W - 1000W - 100Z - 10Y - X) / 9 = (999X + 90Y - 90Z - 999W) / 9 = (111X + 10Y - 10Z - 111W) = 111(X-W) + 10(Y - Z),对于 5 位数,也可以推出这个结论,中间的奇数位减没了,现有 111(X - W),一定是 111 的倍数,结果必然每一位都为 111 的倍数,要满足题意,只需让 Y - Z 等于 0。即判断对应位置数值是否相等,对于某一位置 i ,它的补集 l - i 就是它的对应位置,l 为字符串长度。
#include <bits/stdc++.h>

char str[110];

int main()
{
	while(scanf("%s",str))
	{
		int l=strlen(str);
		if(l<=3)
		{
			printf("YES
");
			continue;
		}
		int flag=1;
		for(int i=1;i<=l/2-1;i++)
		{
			if(str[i]!=str[l-1-i]) flag=0;
		}
		if(flag) printf("YES
");
		else printf("NO
");
	}
	return 0;
}

参考:https://blog.csdn.net/qq_40507857/article/details/80541351

原文地址:https://www.cnblogs.com/NikkiNikita/p/9496195.html