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

这是什么算法!居然过了!郁闷!

Posted by chenxuan123456789 at 2012-08-07 09:06:12 on Problem 1047
#include <stdio.h>
#include <string.h>
char str[100];
char k[100];
void mult(char s[],int n)
{
  int d=0,sum,i,l;
  l=strlen(s);
  for(i=0;i<l;i++)
  {
	  sum=(s[i]-'0')*n+d;
	  d=sum/10;
	  s[i]=sum%10+'0';
  }
  while(d)
  {
	  s[i]=d%10+'0';
	  d/=10;
  }
}
int main()
{
	int i,j,count;
	while(scanf("%s",str)!=EOF)
	{
		strrev(str);
		strcpy(k,str);
		int length;
		length=strlen(str);
		mult(str,length+1);
		strrev(k);
		count=0;
		for(i=0;i<length;i++)
		if(str[i]=='9')
		count++;
		if(count==length)
		printf("%s is cyclic",k);
		else
		printf("%s is not cyclic",k);
		printf("\n");
	}
	return 1;
}

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