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

打算放弃了,discuss里面所有的边界数据都对了,过路人有时间看一下,找到错误吼一声

Posted by lihuiyykl at 2009-08-13 17:03:22 on Problem 1016 and last updated at 2009-08-13 17:49:10
#include<iostream>
#include<string>

using namespace std;
#define MAX 8100

int bitnum(int a)
{
    int num=1;
    while(a/10) num++,a=a/10;
    return num;
}

int powd(int t)
{
    int num=1;
    for(int i=0;i<t;i++) num*=10;
    return num;
}

char *Inventory(char *str)
{
     char temp[MAX];
     int len=strlen(str);
     int arr[10];//用来统计0~9的个数 
     memset(arr,0,10*sizeof(int));
     for(int i=0;i<len;i++)       arr[int(str[i]-'0')]++;
     int j=0;
     for(int i=0;i<10;i++)
     {
         if(arr[i]!=0)
         {
              int num=bitnum(arr[i]);
              while(num)
              {
                        num--;
                        temp[j++]=char('0'+arr[i]/powd(num));
                        arr[i]=arr[i]%powd(num);
              }
              temp[j++]=char('0'+i);
         }
     }
     temp[j]='\0';
     return temp;
}

int main()
{
    char str[MAX];
    char strtemp[MAX];
    char temp[170][MAX];
    while(cin>>str)
    {
         if(strcmp(str,"-1")==0) break;
         int total=1;
         strcpy(strtemp,str);
         strcpy(temp[0],str);
         bool flag=false;
         while(total<=15)
         {
             strcpy(temp[total],Inventory(strtemp));
             if(total==1&&strcmp(temp[total],str)==0) 
             {
                  flag=true;
                  cout<<str<<" is self-inventorying"<<endl;
                  break;
             }
             if(strcmp(temp[total-1],temp[total])==0)
             {
                 flag=true;
                 cout<<str<<" is self-inventorying after "<<total-1<<" steps"<<endl;
                 break;
             }
             for(int i=1;i<total;i++)
             {
                     if(strcmp(temp[i],temp[total])==0)
                     {
                         flag=true;
                         cout<<str<<" enters an inventory loop of length "<<total-i<<endl;
                         break;
                     }
             }
             if(flag) break;
             strcpy(strtemp,temp[total]);
             total++;
         }
         if(!flag) cout<<str<<" can not be classified after 15 iterations"<<endl;
    }
    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