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 llyans at 2012-04-11 20:32:25 on Problem 1016
In Reply To:谁有更多的测试案例啊.谢谢. Posted by:llyans at 2012-04-11 12:09:49
现在可以ac了..
只是把从当前数字得到下一数字的过程改了下.
原来是得到字符串,从小到大排序,然后从头遍历字符串.当当前字符与保存的上一个
字符不同时,输出字符串,因为已经排序,所以输出就是x0x1x2x3等等.
这种方法一直wa.

换成不排序字符串,把字符的值作为数组索引来保存这个字符出现的次数.
用这种方法就ac了..但是我认为第一种方法是可以的..多次测试都没有问题,不过用
第一种方法会慢一些..但为什么oj给出wa真心不知道..哪位能给提示一下?感谢.

#define MAX 100
#define TOINT(x) (x-48)  \



#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 



void deal_input(char*s);
int charcmp(const void*a,const void*b);




int main(void)
{
        char input[MAX];

        while(1){
                memset(input,0,sizeof(input));
                scanf("%s",input);
                if(strcmp(input,"-1")==0)
                        break;
                deal_input(input);
        }
        return 0;
}





int charcmp(const void*a,const void*b)
{
        return*(char*)a> *(char*)b;
}

void deal_input(char*s)
{
        char ori[MAX];
        char pre[MAX];
        char now[MAX];
        char rec[16][MAX];
        int ncnt[10];

        int l;
        int i,j;

        memset(ori,0,sizeof(ori));
        strcpy(ori,s);

        memset(rec,0,sizeof(rec));
        strcpy(rec[0],ori);

        for(i= 1;i<=15;i++){

                memset(now,0,sizeof(now));
                memset(pre,0,sizeof(pre));

                strcpy(pre,rec[i-1]);
                l= strlen(pre);

                memset(ncnt,0,sizeof(ncnt));
                for(j= 0;j<l;j++){
                        ncnt[TOINT(pre[j])]++;
                }
                for(j= 0;j<10;j++){
                        if(ncnt[j]!=0)
                                sprintf(now+strlen(now),"%d%d",ncnt[j],j);
                }

                strcpy(rec[i],now);

                if(strcmp(now,rec[i-1])==0){
                        if(i==1)
                                printf("%s is self-inventorying\n",s);
                        else
                                printf("%s is self-inventorying after %d steps\n",s,i-1);
                        return;
                }

                for(j= i-2;j>=0;j--){
                        if(strcmp(now,rec[j])==0){
                                printf("%s enters an inventory loop of length %d\n",s,i-j);
                                return;
                        }
                }


        }

        printf("%s can not be classified after 15 iterations\n",s);
        return;
}


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