2016 Chinese college Student Program Design Competition (Changchun)-Re-entry of the game

Source: Internet
Author: User

J. Ugly Problem

Test instructions: Divide the large number into a palindrome number of no more than 50

The main point: each time with no more than the large number of palindrome to reduce, the results to be carried out again, note "10" The number of pit points

#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<string>#include<cstdlib>#include<vector>#include<Set>#include<map>using namespacestd;Const Doubleeps=1e-8;intLen;voidSubtractChar*a,Char*b,Char*c) {     for(inti=len-1; i>=0; i--) {C[i]=a[i]-b[i]+'0'; if(c[i]<'0') c[i]+=Ten, a[i-1]--; }}Charstr[2][1005],sub[ -][1005];intMain () {intI,j,k,n; scanf ("%d",&n); GetChar ();  for(intH=1; h<=n;h++) {memset (sub,'0',sizeof(sub)); Gets (str[0]); Len=strlen (str[0]); intOld=1, now=0; intCnt=0;  for(i=0; Str[now][i];) { old^=1, now^=1; if(!STRCMP (Str[old]+i,"Ten") ) {sub[cnt][0]='9'; sub[cnt][1]=0; cnt++; sub[cnt][0]='1'; sub[cnt][1]=0; cnt++;  Break; }             for(j=i;j<=len-1-j+i && str[old][j]<=str[old][len-1-j+i];j++);            strcpy (Sub[cnt],str[old]); if(j<len-1-j+i) {sub[cnt][(i+len-1)/2]--;  for(J= (i+len-1)/2; j>=0&& sub[cnt][j]<'0'; j--) sub[cnt][j]+=Ten, sub[cnt][j-1]--; }             for(j=0; sub[cnt][j]=='0'; j + +);  for(k=j;k<=len-1-k+j;k++) sub[cnt][len-1-k+j]=Sub[cnt][k]; Sub[cnt][len]=0;            Subtract (Str[old],sub[cnt],str[now]);  for(; str[now][i]=='0'; i++); CNT++; } printf ("Case #%d:\n%d\n", h,cnt);  for(i=0; i<cnt;i++)        {            Char*s;  for(s=sub[i];*s=='0'; s++);        Puts (s); }    }    return 0;}
J Ugly Problem

2016 Chinese college Student Program Design Competition (Changchun)-Re-entry of the game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.