Ugly Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Special Judge
Problem Description
Everyone hates ugly problems.
You are given a positive integer. You must represent that number by sum of palindromic numbers.
A palindromic number is a positive integer such that if you write out that integer as a string in decimal without leading zeros, the string is an palindrome. For example, 1 is a palindromic number and 10 is not.
Input
In the first line of input, there is an integer T denoting the number of test cases.
For each test case, there is only one line describing the given integer s (1\leq s \leq 10^{1000}).
Output
For each test case, output “Case #x:” on the first line where x is the number of that test case starting from 1. Then output the number of palindromic numbers you used, n, on one line. n must be no more than 50. en output n lines, each containing one of your palindromic numbers. Their sum must be exactly s.
Sample Input
2
18
1000000000000
Sample Output
Case #1:
2
9
9
Case #2:
2
999999999999
1
Hint
9 + 9 = 18 999999999999 + 1 = 1000000000000
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[];
int ans[][];
int gg[];
int sub(int t,int len)
{
int i;
for(i=len-; i>=; i--)
{
s[i]=s[i]-''-ans[t][i];
if(s[i]<)
{
s[i]+=+'';
s[i-]-=;
}
else s[i]+='';
}
for(i=; i<len; i++)
if(s[i]!='') break;
return i;
}
int main()
{
int i,j,t,T;
while(scanf("%d",&T)!=EOF)
{
getchar();
for(int asd=; asd<=T; asd++)
{
scanf("%s",s);
memset(ans,,sizeof(ans));
int pre=,len=strlen(s);
t=;
while(pre<len)
{
int sign=;
for(i=pre,j=len-; i<=j; i++,j--)
{
ans[t][i]=ans[t][j]=s[i]-'';
if(ans[t][j]>s[j]-'') sign=;
else if(ans[t][j]<s[j]-'')sign=;
}
gg[t]=pre;
if(sign==)
{
i--;
ans[t][i]-=;
while(i>=&&ans[t][i]<)
{
ans[t][i]+=;
ans[t][i-]-=;
i--;
}
for(i=pre,j=len-; i<=j; i++,j--)
ans[t][j]=ans[t][i];
if(ans[t][pre]==)
{
ans[t][len-]=;
gg[t]=pre+;
}
}
pre=sub(t,len);
t++;
}
printf("Case #%d:\n",asd);
printf("%d\n",t);
for(i=; i<t; i++)
{
for(j=gg[i]; j<len; j++)
printf("%d",ans[i][j]);
printf("\n");
}
}
}
return ;
}