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:哪位高手帮忙看看啊(C代码),怎么老是WA啊??都快崩溃了.........

Posted by lynn83 at 2006-02-10 12:38:09 on Problem 1016
In Reply To:哪位高手帮忙看看啊(C代码),怎么老是WA啊??都快崩溃了......... Posted by:lynn83 at 2006-02-09 19:51:20
到底哪儿错了,或是给个测试数据!
> #include<stdio.h>
> #include<string.h>
> 
> void inventory(char *a, char *b)
> {
> 	int i, j, tmp[10]={0};
> 	for(i=0; i<strlen(b); i++) tmp[b[i]-'0']++;
> 	for(i=0, j=0; i<10; i++) {
> 		if(tmp[i]>0) {
> 			if(tmp[i]>=10) a[j++]=tmp[i]/10+'0';
> 			a[j++]=tmp[i]%10+'0';
> 			a[j++]=i+'0';
> 		}
> 	}
> 	a[j]='\0';
> }
> 
> int main()
> {
> 	char num[16][100];
> 	int i, n;
> 	while(1) {
> 		scanf("%s", num[0]);
> 		if(strcmp(num[0], "-1")==0) break;
> 		for(n=0; n<15; n++) {
> 			inventory(num[n+1], num[n]);
> 			if(strcmp(num[n+1], num[n])==0) {
> 				if(n==0) printf("%s is self-inventorying\n", num[0]);
> 				else printf("%s is self-inventorying after %d steps\n", num[0], n);
> 				break;
> 			}
> 			else {
> 				for(i=n-1; i>=0; i--) if(strcmp(num[n+1], num[i])==0) break;
> 				if(i>=0) {
> 						printf("%s enters an inventory loop of length %d\n", num[0], n+1-i);
> 						break;
> 				}
> 			}
> 
> 		}
> 		if(n==15) printf("%s can not be calssified after 15 iterations\n", num[0]);
> 	}
> 	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