HDU - 5920 Ugly Problem
这个题限时训练的时候是3次尝试但是没有做出来的,所以我压根就没看(……可以说是非常诚实的了),后来找题解看了看,其实是一个分奇偶的大数减,但是把……我写着写着写迷糊了,就抄了一个交的。
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≤s≤101000).
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
抄的代码的来源https://blog.csdn.net/qq_25576697/article/details/76850938
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#define N 1010
#define ll long long
//#define INF 1e18
ll const INF = 1e18;
using namespace std;
char a[N],b[N],c[N],ans[N][N];
int len,num;
int main()
{
int t,i,j,k,m,ta,tb,n,tc;
bool flag,jw;
scanf("%d",&t);
for(k=1;k<=t;k++){
scanf("%s",a);
len=strlen(a);
num=0;
while(len>=1){
flag=0;
b[len>>1]=a[len>>1];
for(i=len/2-1;i>=0;i--){
if(a[i]!=a[len-1-i]&&!flag){
flag=1;
b[i]=b[len-1-i]=a[i]<a[len-1-i]?a[i]:a[len-1-i];
}
else{
b[i]=b[len-1-i]=a[i];
}
}
b[len]=0;
if(!flag){
strcpy(ans[num++],a);
break;
}
if(b[0]=='0'){
if(a[0]=='1'){
strcpy(ans[num++],"1\0");
for(i=0;i<len-1;i++){
ans[num][i]='9';
}
ans[num++][len-1]=0;
}
else{
m=a[0]-'0';
ans[num][0]=(char)(11-m+'0');
ans[num++][1]=0;
ans[num][0]=ans[num][len-1]=(char)(a[0]-1);
for(i=1;i<len-1;i++){
ans[num][i]='9';
}
ans[num++][len]=0;
}
b[0]=a[0];
for(i=1;i<len;i++){
b[i]='0';
}
b[len]=0;
}
else{
strcpy(ans[num++],b);
}
jw=false;
for(i=len-1;i>=0;i--){
ta=a[i]-'0';
tb=b[i]-'0';
n=(10+a[i]-b[i]-jw)%10;
c[i]=n+'0';
jw=(a[i]-b[i]-jw)<0;
}
c[len]=0;
tc=0;
while(c[tc]=='0')
tc++;
strcpy(a,c+tc);
len=strlen(a);
}
printf("Case #%d:\n%d\n",k,num);
for(int i=0;i<num;i++)
cout<<ans[i]<<endl;
}
return 0;
}