HDU5920【模拟】
模拟题这种东西啊~就是自己读题,自己打,没有别的方法。。。贴份6000+b的code跑;
#include <bits/stdc++.h> using namespace std; //typedef long long LL; const int N=1e5+10; char s[N]; //输入串 char tmp[N];//每次要处理的串; char t1[N]; //要处理的前半 char t3[N]; char t2[N]; //后半; //答案串,和答案数量 char ans[55][N]; int res; char jian[N]; int cal(char *a, char *b)//a-b { int jie = 0; int lena = strlen(a); int lenb = strlen(b); int i,j; for(i = lenb-1, j = lena-1; i >= 0 || j >= 0; i--,j--) { if(i >= 0) a[j] = a[j]-(b[i]+jie)+'0'; else a[j] = a[j]-jie; if(a[j] < '0') { a[j] += 10; jie = 1; } else jie = 0; } int k; for(int i = 0; i < lena; i++) { if(a[i] != '0') { k = i; break; } } int h = 0; for(int i = k; i < lena; i++) a[h++] = a[i]; if(!h) a[h++]='0'; a[h] = '\0'; strcpy(jian,a); } int main() { char one[5]; strcpy(one,"1"); int cas=1; int T; scanf("%d",&T); while(T--) { scanf("%s",tmp); res=0; while(1) { int len=strlen(tmp); if(len==1) { strcpy(ans[res++],tmp); break; } if(len%2) //奇数 { char mid; int num1,num2,num3; num1=num2=num3=0; for(int i=0;i<len/2;i++) t3[num3++]=tmp[i]; for(int i=len/2-1;i>=0;i--) t1[num1++]=tmp[i]; mid=tmp[len/2]; for(int i=len/2+1;i<len;i++) t2[num2++]=tmp[i]; t1[num1]='\0'; t2[num2]='\0'; t3[num3]='\0'; int temp=strcmp(t2,t1); if(temp>0) { int zsq=0; for(int i=num1-1;i>=0;i--) ans[res][zsq++]=t1[i]; ans[res][zsq++]=mid; for(int i=0;i<num1;i++) ans[res][zsq++]=t1[i]; ans[res][zsq]='\0'; cal(tmp,ans[res]); res++; strcpy(tmp,jian); } else if(temp==0) { strcpy(ans[res],tmp); res++; break; } else { if(mid=='0') { cal(t3,one); if(t3[0]=='0') { strcpy(ans[res++],"1"); strcpy(ans[res++],"99"); break; } int zsq=0; int jian_len=strlen(jian); for(int i=0;i<jian_len;i++) ans[res][zsq++]=jian[i]; ans[res][zsq++]=mid; for(int i=jian_len-1;i>=0;i--) ans[res][zsq++]=jian[i]; ans[res][zsq]='\0'; cal(tmp,ans[res]); strcpy(tmp,jian); res++; } else { mid--; int zsq=0; for(int i=0;i<num3;i++) ans[res][zsq++]=t3[i]; ans[res][zsq++]=mid; for(int i=num3-1;i>=0;i--) ans[res][zsq++]=t3[i]; ans[res][zsq]='\0'; cal(tmp,ans[res]); strcpy(tmp,jian); res++; } } } else //偶数 { int num1,num2,num3; num1=num2=num3=0; for(int i=0;i<len/2;i++) t3[num3++]=tmp[i]; for(int i=len/2-1;i>=0;i--) t1[num1++]=tmp[i]; for(int i=len/2;i<len;i++) t2[num2++]=tmp[i]; t1[num1]='\0'; t2[num2]='\0'; t3[num3]='\0'; int temp=strcmp(t2,t1); if(temp>0) { int zsq=0; for(int i=num1-1;i>=0;i--) ans[res][zsq++]=t1[i]; for(int i=0;i<num1;i++) ans[res][zsq++]=t1[i]; ans[res][zsq]='\0'; cal(tmp,ans[res]); strcpy(tmp,jian); res++; } else if(temp==0) { strcpy(ans[res],tmp); res++; break; } else { cal(t3,one); if(jian[0]=='0') { strcpy(ans[res++],"1"); strcpy(ans[res++],"9"); break; } int zsq=0; int jian_len=strlen(jian); for(int i=0;i<jian_len;i++) ans[res][zsq++]=jian[i]; for(int i=jian_len-1;i>=0;i--) ans[res][zsq++]=jian[i]; ans[res][zsq]='\0'; cal(tmp,ans[res]); strcpy(tmp,jian); res++; } } } printf("Case #%d:\n",cas++); printf("%d\n",res); for(int i=0;i<res;++i) printf("%s\n",ans[i]); } return 0; }