# 构造 D - Finals in arithmetic ★ ★

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define L(i) i<<1
#define R(i) i<<1|1
#define INF  0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-9
#define maxn 100100
#define MOD 1000000007

char str[maxn];
char ans[maxn];
int s[maxn];
int n;
int judge()
{
for(int i = 0; i < n / 2; )
{
int l = i,r = n - 1 - i;
if(s[l] == s[r])
i++;
else if(s[l] == s[r] + 1 || s[l] == s[r]+11)
{
s[l]--;
s[l+1] += 10;
}
else if(s[l] == s[r] + 10)
{
s[r] += 10;
s[r-1]--;
}
else
return 0;
}
if(n & 1)
{
if(s[n/2] & 1 || s[n/2] > 18 || s[n/2] < 0)
return 0;
ans[n/2] = s[n/2] / 2 + '0';
}
for(int i = 0; i < n / 2; i++)
{
if(s[i] > 18 || s[i] < 0)
return 0;
ans[i] = (s[i] + 1) / 2 + '0';
ans[n-i-1] = s[i] / 2 + '0';
}
return ans[0] > '0';
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t,C = 1;
//scanf("%d",&t);
while(scanf("%s",str) != EOF)
{
n = strlen(str);
for(int i = 0; i < n; i++)
s[i] = str[i] - '0';
if(judge())
printf("%s\n",ans);
else if(str[0] == '1' && n > 1)
{
for(int i = 0; i < n; i++)
s[i] = str[i+1] - '0';
s[0] += 10;
n--;
if(judge())
printf("%s\n",ans);
else
printf("0\n");
}
else
printf("0\n");
}
return 0;
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：构造 D - Finals in arithmetic ★ ★ 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)