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 xfxyjwf at 2005-05-19 09:53:15 on Problem 1047
In Reply To:又是说答案错误了!是怎么回事啊,我想了很多遍了哦。能否给我多些测试用例。麻烦了。各位高手!我真的投降了! Posted by:plumage at 2005-05-18 23:33:49
/*
贴一份代码,给你参考一下。
主函数里有一个循环:
while(scanf("%s",str) != EOF)
{
     //...
}
用来输入多组数据。
如果用cin:
cin >> str;
while(cin) //or while(!cin.fail())
{
     //...
     cin >> str;
}
*/
#include <stdio.h>
#include <string.h>

int num[100],temp[100];
int n;
void cpy(int num1[100],int num2[100],int n)
{
	int i;
	for(i=1;i<=n;i++)
		num1[i] = num2[i];
}
int cmp(int num1[100],int num2[100],int n)
{
	int i;
	for(i=1;i<=n;i++)
		if(num1[i]!=num2[i])
			return 0;
	return 1;
}
void shl(int num[100],int n)
{
	int i,temp = num[1];
	for(i=1;i<n;i++)
		num[i] = num[i+1];
	num[n] = temp;
}
int mutiply(int num[100],int n,int x)
{
	int i,j;
	j = 0;
	for(i=n;i>=1;i--)
	{
		num[i] = num[i]*x+j;
		j = num[i]/10;
		num[i] = num[i]%10;
	}
	if(j > 0)
		return 0;
	return 1;
}


int main()
{
	int i,j;
	char str[100];
	while(scanf("%s",str) != EOF)
	{
		n = strlen(str);
		for(i=1;i<=n;i++)
			num[i] = str[i-1]-'0';
		for(i=2;i<=n;i++)
		{
			cpy(temp,num,n);
			if(!mutiply(temp,n,i))
				break;
			for(j=1;j<=n;j++)
			{
				shl(temp,n);
				if(cmp(num,temp,n))
					break;
			}
			if(j > n)
				break;
		}
		if(i <= n)
		{
			printf("%s is not cyclic\n",str);
		}
		else
		{
			printf("%s is cyclic\n",str);
		}
	}
	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