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

我是第一次用C做题目.请各位帮忙看下我这有什么问题

Posted by Zonnix at 2008-03-17 20:09:50 on Problem 1002
我是第一次用C做题目,搞了好一阵子终于可以运行了- -!
不过好像出了些比较严重的错误...请各位帮忙指正一下~
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define CREAT (struct num *) malloc (sizeof (struct num))
struct num
{
	char s[8];
	int amount;
	struct num *next;
};

void main ()
{
	
	int a,i,j=0;
	char scnum [50],cmp[8],temp[8]; 
	struct num * head,* p1;
	char change (char a[],char b[]);
	struct num * rank (struct num *h,char a[]);
	scanf ("%d",&a);
	for (i=0;i<a;i++)
	{
		if (i==0) 
		{
			head=(struct num *) malloc (sizeof (struct num)); 
			head->next=NULL;
			scanf ("%s",scnum);
			change (scnum,temp);
			strcpy (head->s,temp);
		}
		else 
		{
			scanf ("%s",scnum);
			change (scnum,temp);
			strcpy (cmp,temp);
			head=rank (head,cmp);
		}
	}
	p1=head;
	if (p1->next==NULL) printf ("perfect");
	else
	while (p1!=NULL)
	{
		printf ("%s %d",p1->s,p1->amount);
		p1=p1->next;
	}
}	

char change (char a[],char b[])
{
	int i,n;
	for (i=0,n=0;i<50,n<8;i++)
	{
		if (n==3) 
		{
			b[3]='-';
			n++;
		}
		switch(a[i])
		{
			case'A':
			case'B':
			case'C':b[n]=2;n++;break;
			case'D':
			case'E':
			case'F':b[n]=3;n++;break;
			case'G':
			case'H':
			case'I':b[n]=4;n++;break;
			case'J':
			case'K':
			case'L':b[n]=5;n++;break;
			case'M':
			case'N':
			case'O':b[n]=6;n++;break;
			case'P':
			case'R':
			case'S':b[n]=7;n++;break;
			case'T':
			case'U':
			case'V':b[n]=8;n++;break;
			case'W':
			case'X':
			case'Y':b[n]=9;n++;break;
			default:break;
		}
	}
}

struct num * rank (struct num * h,char a[])
{
	struct num * p0,* p1,* p2;
	p1=h;
	p0=CREAT;
	strcpy (p0->s,a);
	p0->amount=1;
	while (strcmp (p0->s,p1->s)>0 && (p1->next!=NULL))
	{
		p2=p1;
		p1=p1->next;
	}
	if (strcmp (p0->s,p1->s)==0)
	{
		p1->amount+=1;
		free (p0);
	}
	else if (strcmp (p0->s,p1->s)<0)
	{
		p0->next=p1;
		p2->next=p0;
	}
	else
	{
		p1->next=p0;
		p0->next=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