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 Callyou at 2004-03-05 13:20:43 on Problem 1583
//自我感觉良好,但是一提交就Wrong Answer.
//请老大们看看是那种情况没有考虑到。
#include <iostream.h>
#include <string.h>
#include <stdlib.h>

struct Node
{
	char word [81];
	int times;
	Node * next;
};

inline int isValid ( char ch )
{
	int flags = 0;
	char sample [] = ",.;\'`\"()/:-";
	if ( ( ch >= 'A' && ch <= 'Z' ) ||
		( ch >= 'a' && ch <= 'z' ) ||
		( ch >= '0' && ch <= '9' ) )
		return 1;
	for ( int i = 0; i < 11; i++ )
		if ( ch == sample [i] )
		{
			flags = 1;
			break;
		}
	if ( flags )	
		return 0;
	exit (0);
}

void log ( Node * head, char * word )
{
	Node * current;
	for ( current = head; current -> next != NULL; current = current -> next )
	{
		if ( strcmp ( current -> next -> word, word ) == 0 )
		{
			current -> next -> times ++;
			break;
		}
		if ( strcmp ( current -> next -> word, word ) > 0 )
		{
			Node * p = new Node;
			strcpy ( p -> word, word );
			p -> times = 1;
			p -> next = current -> next;
			current -> next = p;
			break;
		}
	}
	if ( current -> next == NULL )
	{
		Node * p = new Node;
		strcpy ( p -> word, word );
		p -> times = 1;
		p -> next = current -> next;
		current -> next = p;
	}
}

void deal ( Node * head, char * p )
{
	char temp [81];
	int k = 0, front = 0, rear = 0;
	while ( p [k] )
	{		
		while ( ! isValid ( p [k] ) )
			k++;
		front = k;
		while ( isValid ( p [k] ) )
			k++;
		rear = k;
		for ( int i = front; i < rear; i++ )
			temp [ i - front ] = p [i];
		temp [ i - front ] = 0;
		log ( head, temp );
		cout << temp << endl;
	}
}

void main()
{
	char buff[81];
	Node * head, * current;
	head = new Node;
	head -> word [0] = 0;
	head -> times = 0;
	head -> next = NULL;
	cin >> buff;
	while ( cin )
	{
		strlwr ( buff );
		deal ( head, buff );
		cin >> buff;
	}
	int max = 0;
	for ( current = head -> next; current != NULL; current = current -> next )
		if ( max < current -> times )
			max = current -> times;
	cout << max << " occurrences\n";
	for ( current = head -> next; current != NULL; current = current -> next )
		if ( current -> times == max )
			cout << current -> word << endl;
}

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