# I. Reversion Count

I. Reversion Count
Description:

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), 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”.

10
13

YES

YES

#include <stdio.h>
#include <stdlib.h>
char a[101],b[101];

int isonly(int c){
int a=c%10;
while(c){
int c2=c%10;
if(c2!=a)
return 0;
c/=10;
}
return 1;
}

int main(void)
{
int len,i,j;
int c;
for(;;){
len=0;

for(i=0;;i++){
scanf("%c",&a[i]);
if(a[i]=='\n')
break;
len++;
}
for(j=len,i=0;j>=0;j--,i++){
b[j]=a[i];
}

c=(atoi(a)-atoi(b))/9;
if(c<0)
c=-c;
if(c==0)
printf("YES\n");
else if(isonly(c))
printf("YES\n");
else
printf("NO\n");
}

return 0;
}



#include<iostream>
#include<algorithm>
using namespace std;

string x;
int z[100],y[100];
int len;

void turn()
{
len=0;
for(int i=x.size()-1;i>=0;--i)
{
y[i]=x[i]-'0';
z[len++]=x[i]-'0';
}
}

bool com()
{
for(int i=len-1;i>=0;--i)
if(z[i]!=y[i])
{
if(z[i]<y[i])
{
swap(z,y);
break;
}
else
break;
}

for(int i=0;i<len;++i)
{
if(z[i]<y[i])
{
z[i+1]-=1;
z[i]+=10;
z[i]-=y[i];
}
else
z[i]-=y[i];
}

--len;
while(!z[len]&&len>0)
--len;
if(len==0)	return true;

for(int i=len;i>=0;--i)
{
if(z[i]>=9||z[i]==0)
{
if(i!=0)	z[i-1]+=z[i]%9*10;
z[i]/=9;
}
else
{
if(i!=0)	z[i-1]+=z[i]*10;
z[i]=0;
}
}
while(!z[len]&&len>0)
--len;
if(len==0)	return true;
for(int i=1;i<=len;++i)
if(z[i]!=z[i-1])	return false;
return true;
}

int main()
{
while(cin>>x)
{
turn();
if(com())
cout<<"YES\n";
else
cout<<"NO\n";
}

return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120