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 libanghui at 2005-10-03 13:53:41 on Problem 2569
#include<stdio.h>
#include<iostream.h>
#include<string.h>
#include <stdlib.h>

struct pp
{
	int start;
	int num;
}hh[5600];

char s[5600];


int compare (const void * a, const void * b)
{
  pp *x= (pp*)a,*y=(pp *)b;
  if(x->num==y->num)
	 {
	  if(s[x->start]==s[y->start])
		  return s[x->start+1]-s[y->start+1];
	  else 
	  return s[x->start]-s[y->start];
	 }
  else
  return -(x->num-y->num);
}

int main()
{
	
	char c[100];
	int n,i,j,len;
	int sum,count;
	
	while(cin>>n&&n)
	{
			
		s[0]='\0';

		for(i=1;i<=n;i++)
		{
			gets(c);
			strcat(s,c);
		}
		len=strlen(s);
	//	cout<<s<<endl;
		sum=len-1;
		for(i=0;i<len-1;i++)
		{
			count=0;
			for(j=i+1;j<len-1;j++)
				if(s[i]==s[j]&&s[i+1]==s[j+1])
					count++;
			hh[i].start=i;hh[i].num=count+1;

		}

		qsort (hh, len-1, sizeof(pp), compare);

		count=0;
		for(i=0;i<len-1;i++)
		{
			for(j=0;j<i;j++)
				if(s[hh[i].start]==s[hh[j].start]&&s[hh[i].start+1]==s[hh[j].start+1]) break;
			if(j==i) 
			{
				printf("%c%c %d %0.6f\n",s[hh[i].start],s[hh[i].start+1],hh[i].num,hh[i].num*1.0/sum);
				count++;
			}
			if(count==5) {break;}
		}

		printf("\n");

	
		
	}
	return 1;
}



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