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

不知道为什么说我WA了! 各位能给我点数据吗?

Posted by cygnus157 at 2006-01-05 08:54:45 on Problem 1047
#include <iostream>
#include <string>
using namespace std;

class List;
class ListNode
{
	friend class List;
public:
	ListNode ()
	{
		link = NULL;
	}
	int data;
	ListNode * link;
	ListNode * rlink;
};
class List
{
public:
	List()
	{
		first = last = NULL;
	}
private:
	ListNode * first, * last;
};

void main()
{
	unsigned int i;
	string n;
loop:	while( cin >>n )
	{
		ListNode * p,* last;
		ListNode * first = new ListNode();
		last = NULL;
	    
		first->data = n[0] - 48;
		//&Ecirc;&auml;&Egrave;&euml;
		for(i = 1; i < n.length(); i++) 
		{
			int num = n[i] - 48;

			ListNode * newnode = new ListNode();

			if ( last == NULL )
			{
				newnode->data = num;
				newnode->link = first;
				first->rlink = newnode;//
				p = newnode;
				last = p;
			}
			else
			{
				newnode->data = num;
				newnode->link = p;
				p->rlink = newnode;
				p = p->rlink;
				last = p;
			}
		}
		first->link = last;
		last->rlink = first;
		ListNode * current;
		//&frac14;&AElig;&Euml;&atilde;
		int x(0);
		ListNode * p2,* temp,* temp2;

		for( i = 1; i < n.length(); i++ )
		{
			temp2 = NULL;
			temp = new ListNode();
			current = p;
			do
			{
				p2 = new ListNode();
				if( temp2 == NULL )
				{
					temp2 = p2;
				}
				p2->data = current->data*(i + 1)%10 + x;
				x = 0;
				if( current->data*(i + 1) >= 10 )
				{
					x = current->data*(i + 1)/10;
				}                                    
				if( p2->data >= 10 )
				{
					x += p2->data/10;
					p2->data = p2->data%10;				
				}  
				current = current->link;
				p2->link = temp;
				temp = p2;
			}  while ( current != first->link );

			//&Aring;&ETH;&para;&Iuml;
			current = temp;
			while( 1 )
			{
   				int ip(0);
				while( current->data != last->data )
				{
					last = last->rlink;
					ip++;
					if( ip == n.length() )
					{
						cout<<n<<" is not cyclic"<<'\n';
						goto loop2;
					}
				}
				while(1)
				{
					if( (current->data) == (last->data) )
					{
   						current = current->link;
						last = last->rlink;
						if( current->link == NULL )
						{	
							break;
						}
					}
					else
					{
						if( current->data != last->data )
						{
							int ip(0);
							while( current->data != last->data )
							{
								last = last->rlink;
								ip++;
								if( ip == n.length() )
								{
									cout<<n<<" is not cyclic"<<'\n';
									goto loop2;
								}
							}
						}
						else
						{
							cout <<n<<" is not cyclic"<<'\n';
							goto loop2;
						}
					}
				}
				break;				
			}
		}
		cout<<n<<" is cyclic"<<'\n';
		//&Ecirc;&Iacute;·&Aring;
loop2:		ListNode * d1,* d2;
		current = p;
		while( temp->link != NULL )
		{		
			d1 = current;
			d2 = temp;
			temp = temp->link;
			current = current->link;
			delete d1;
			delete d2;
			d1 = d2 = NULL;
		}
	}
}

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