Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求教,牛人看看呗。OLE。。。

Posted by lolihunter at 2009-07-15 12:22:19 on Problem 1489
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
char strx[5][50]={"|||||||||||||||||||||||||||||||||||||||||||||||||",
                  "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn",
                  "9999999999999999999999999999999999999999999999999",
                  "8888888888888888888888888888888888888888888888888",
                  "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"
                  };
void change(int a,char * str)
{
      int q[6];
      int k;
      q[5]=a/10000;
      q[4]=(a%10000)/1000;
      q[3]=(a%1000)/100;
      q[2]=(a%100)/10;
      q[1]=a%10;
      for(k=1;k<6;k++)
        switch(k)
        { 
          case 1:if(q[1]==0)
                    break;
                 strncat(str,strx[0],q[1]);
                 strcat(str," ");
                 break;
          case 2:if(q[2]==0)
                    break;
                 strncat(str,strx[1],q[2]);
                 strcat(str," ");
                 break;
          case 3:if(q[3]==0)
                    break;
                 strncat(str,strx[2],q[3]);
                 strcat(str," ");
                 break;
         case 4:if(q[4]==0)
                    break;
                 strncat(str,strx[3],q[4]);
                 strcat(str," ");
                 break;
         case 5:if(q[5]==0)
                    break;
                 strncat(str,strx[4],q[5]);
                 strcat(str," ");
                 break;
        }

        return ;
};                  
                  
             
int main()
{
  char str1[64],str2[64],str[64],strr[40][64],stru[64];
  int a,b,i,j,k,temp,sum,mark[30],num[30];      
  int q[6];
  while(gets(str1))
  {
    
    gets(str2);
    for(i=0,b=0;i<strlen(str2);i++)
    {
      switch (str2[i])
      {
        case '|':b+=1;break;
        case 'n':b+=10;break;
        case '9':b+=100;break;
        case '8':b+=1000;break;
        case 'r':b+=10000;break;
      }                        
    }/*  计算出乘数;*/
    for(i=0,a=0;i<strlen(str1);i++)
    {
      switch (str1[i])
      {
        case '|':a+=1;break;
        case 'n':a+=10;break;
        case '9':a+=100;break;
        case '8':a+=1000;break;
        case 'r':a+=10000;break;
      }                        
    }/*  计算出被乘数;*/
    memset(mark,0,sizeof(mark));
    memset(num,0,sizeof(num));   
    /*memset(strr,0,sizeof(strr));
    
    memset(stru,0,sizeof(stru));*/
    
    for(i=0;i<40;i++)
      for(j=0;j<64;j++)
        strr[i][j]=0;
    for(i=0;i<64;i++)
    {
      stru[i]=0;
    } 
      
    for(i=28,sum=0;i>=0;i--)
    {
      temp=pow(2,i);
      if(sum+temp>b)
        continue;
      sum+=temp;
      mark[i]=1;    
      if(sum==b)
        break;              
    }/*标记出相加数的位置*/
    for(i=28;i>=0;i--)
      if(mark[i]==1)
      {
        j=i;
        break;              
      }/*找到纵队的列数 */ 
      
      
    for(i=1,num[0]=a;i<=j;i++)
    {
      num[i]=num[i-1]*2;               
    }
    for(i=0,sum=0;i<=j;i++)
    {
      if(mark[i])
        sum+=num[i];               
    }
    
    for(i=0;i<=j;i++)
    {
      change(num[i],strr[i]);
    }
    
    for(i=0;i<=j;i++)
    {
      temp=(int)pow(2,i);
      for(k=0;k<64;k++)
        str[k]=0;
      change(temp,str);
      if(mark[i])
      {
        strcat(str,"*");
        printf("%-34s%s\n",str,strr[i]);
      }
      else
        printf("%-34s%s\n",str,strr[i]);                                
    }
    change(sum,stru);
    printf("The solution is: %s\n",stru);       
  }  
  return 0;    
}



Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator