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

为什么runtime error?谢了

Posted by DavidCameron at 2017-02-11 10:34:31 on Problem 1007
#include<stdio.h>
#include<stddef.h>

struct node
{
int val;
char* str;
node* nxt;
};

void insert(node* head,node* nn)
{
if(head==NULL)
head=nn;
else if(head->val>nn->val)
{
nn->nxt=head;
head=nn;
}
else
{
node* p=head;
while(p+1!=NULL)
while((p+1)->val<=nn->val)
p++;
p->nxt=nn;
}
}

int unsortedness(char* str)
{
char* p1=str;
int usn;
char* p2=p1+1;
while(p2!='\0')
{
if(*p2<*p1)
usn++;
}
if(p1+1!='\0')
usn+=unsortedness(p1+1);
return usn;
}

int main()
{
int len,n;
node* head=NULL;
scanf("%d%d",&len,&n);
while(n-->0)
{
char *p;
scanf("%s",p);
node *np=new node;
np->str=p;
np->val=unsortedness(p);
insert(head,np);
}
while(head++!=NULL)
printf("%s\n",head->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