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

一次AC ,但是也发现测试数据不够严谨。呵呵。11111111明显不是循环数,但是也能通过

Posted by chenjin1st at 2011-11-24 19:23:48 on Problem 1047
代码 如下。但是没有注释。呵呵。
、#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 65
int count(char data1[],char data2[],char data3[]);
int main(){
	char init[N],*data1,*data2,*data3,back[N];
	int len,i;
	while(scanf("%s",init)!=EOF){
		len=(int)strlen(init);i=0;
		while(init[i]){
			if(init[i]!='0')
				break;
			i++;
		}
		if(len==i){
			printf("%s is cyclic\n",init);
		}else{
			data1=(char *)malloc((len+2)*sizeof(char));
			data2=(char *)malloc(3*sizeof(char));
			data3=(char *)malloc((len+3)*sizeof(char));
			for(i=0;i<=len;i++){
				data1[i]='0';
				data3[i]='0';
			}
			data1[i]='\0';data3[i]='0';data3[i+1]='\0';
			strcpy(data1+1,init);
			data2[0]=(len+1)/10+'0';data2[1]=(len+1)%10+'0';data2[2]='\0';
			count(data1,data2,data3);
			i=len+1;
			while(data3[i]){
				if(data3[i]!='9')
					break;
				i--;
			}
			if(i==1)
				printf("%s is cyclic\n",init);
			else
				printf("%s is not cyclic\n",init); 
			free(data1);free(data2);free(data3);
		}
	}
	return 0;
}
int count(char data1[],char data2[],char data3[]){
	int data_1,data_2,unit,decade,value;
	int len1,len2,i,j,k;
	char **mid;
	len1=(int)strlen(data1);
	len2=(int)strlen(data2);
	mid=(char **)malloc(2*sizeof(char **));
	mid[0]=(char *)malloc((len1+2)*sizeof(char));
	mid[1]=(char *)malloc((len1+2)*sizeof(char));
	for(j=0;j<len1+1;j++){
		mid[0][j]='0';
		mid[1][j]='0';
	}
	mid[0][j]='\0';mid[1][j]='\0';
	for(j=len2-1,k=0;j>=0;j--){
		unit=decade=0;
		for(i=len1-1;i>=0;i--){
			data_1=data1[i]-'0';
			data_2=data2[j]-'0';
			value=data_1*data_2+decade;
			unit=value%10;
			decade=value/10;
			mid[k][i-k+1]=unit+'0';
		}
		k++;
	}
	unit=decade=0;
	for(i=len1;i>=0;i--){
		data_1=mid[0][i]-'0';
		data_2=mid[1][i]-'0';
		value=data_1+data_2+decade;
		unit=value%10;
		decade=value/10;
		data3[i]=unit+'0';
	}
	free(mid[0]);free(mid[1]);free(mid);
	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