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

RE了很久啊,很费解,求高手指点一番

Posted by wpsxiaowang1 at 2012-01-23 20:14:50 on Problem 1016
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char str[82],str1[16][82],str3[82],str4[82],str5[82];
int fu[82],fu1[82];
char *func1(char st[])
{
int lenth,i,j,k,l;
int c;
memset(str3,0,sizeof(str3));
memset(fu,0,sizeof(fu));
memset(fu1,0,sizeof(fu1));
lenth=strlen(st);
for(j=0;j<lenth;j++)
{
   for (i=0;i<lenth-j-1;i++)
    if (st[i]>st[i+1])
    {
    c=st[i];
    st[i]=st[i+1];
    st[i+1]=c;
    }
}
for(i=0;i<lenth;i++)
{
    fu[i]=st[i]-48;
}
    i=0;
    l=0;
  while(i<lenth)
  {
      c=fu[i];
      j=0;
      for(k=i;k<lenth;k++)
      {
          if(fu[k]==c)
          j++;
          else
          break;
      }
      i+=j;
      fu1[l++]=j;
      fu1[l++]=c;
  }
  fu1[l]=-1;
  for(i=0;fu1[i]!=-1;i++)
  {
      if(fu1[i]>=10)
      {
      for(j=l;j>=i;j--)
      {
          fu1[j+1]=fu1[j];
      }
      c=fu1[i];
      fu1[i]=c/10;
      fu1[i+1]=c%10;
      }
  }
  for(i=0;fu1[i]!=-1;i++)
  {
      str3[i]=fu1[i]+48;
  }
  str3[i]='\0';
  return str3;
}
int main()
{
    int i,flag,j;
    scanf("%s",str);
    getchar();
    sscanf(str,"%s",str5);
    while(strcmp(str,"-1"))
    {
        memset(str1,0,sizeof(str1));
        flag=0;
        sscanf(func1(str),"%s",str1[0]);
        for(i=1;i<15;i++)
        {
        memset(str4,0,sizeof(str4));
        strcpy(str4,str1[i-1]);
        sscanf(func1(str4),"%s",str1[i]);
        }
        for(i=0;i<15;i++)
        {
            if(strcmp(str5,str1[i])==0)
            {
                if(i==0)
                {
                    printf("%s is self-inventorying\n",str5);
                    flag=1;
                    break;
                }
                else
                {
                    printf("%s enters an inventory loop of length %d\n",str5,i+1);
                    flag=1;
                    break;
                }
            }

        }
        if(flag==0)
        {
            for(i=0;i<15;i++)
            {
                if(flag!=0)
                break;
                for(j=i+1;j<15;j++)
                {

                    if((strcmp(str1[i],str1[j])==0)&&(j-i)==1)
                    {
                        printf("%s is self-inventorying after %d steps\n",str5,i+1);
                        flag=1;
                        break;
                    }
                    if(strcmp(str1[i],str1[j])==0)
                    {
                        printf("%s enters an inventory loop of length %d\n",str5,j-i);
                        flag=1;
                        break;
                    }
                }

            }
        }
        if(flag==0)
        {
          printf("%s  can not be classified after 15 iterations\n",str5);
        }
        memset(str,0,sizeof(str));
        memset(str5,0,sizeof(str5));
        scanf("%s",str);
        strcpy(str5,str);
    }
    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