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 了n次,不知错在哪,求大家指点,万分感激

Posted by alphauestc at 2009-03-24 23:05:45 on Problem 1002
#include<iostream>
using namespace std;

struct dot
{
	long data;
	dot *n;
};

int num;
long *q;
char (*p)[7];
char tt;
class poj1002
{
	int s;int t;int count;dot *ps;dot *pss;dot* tps;dot* tpss;//num表示输入多少个号码,q指向转换后的数组,count用来记重复多少次,ps用来指重复的数;pss用来指重复的次数
public:
	poj1002()
	{
		count=1;
		ps=new dot;
		pss=new dot;
		tps=ps;
		tpss=pss;
	}
	void input()
	{
		//scanf("%d",&num);
		p=new char [num+1][7];
		q=new long[num];
		for(int j=1;j<=num;j++)
		{
			for(int k=0;k<7;k++)
			{
				do
				{
                    p[j][k]=getchar();
				}while(p[j][k]=='-'||p[j][k]=='\n');
				switch(p[j][k])
				{
				case 'A':
				case 'B':
				case 'C':p[j][k]='2';break;
				case 'D':
				case 'E':
				case 'F':p[j][k]='3';break;	
				case 'G':
				case 'H':
				case 'I':p[j][k]='4';break;
				case 'J':
				case 'K':
				case 'L':p[j][k]='5';break;
				case 'M':
				case 'N':
				case 'O':p[j][k]='6';break;
				case 'P':
				case 'R':
				case 'S':p[j][k]='7';break;
				case 'T':
				case 'U':
				case 'V':p[j][k]='8';break;
				case 'W':
				case 'X':
				case 'Y':p[j][k]='9';break;
				}
			}
		}
	}
	void change()
	{
		for(int i=1;i<=num;i++)
		{//cout<<p[i][0]<<' '<<p[i][1]<<' '<<p[i][2]<<' '<<p[i][3]<<' '<<p[i][4]<<' '<<p[i][5]<<' '<<p[i][6]<<'*';
			
			q[i]=(p[i][0]-48)*1000000+(p[i][1]-48)*100000+(p[i][2]-48)*10000+(p[i][3]-48)*1000+(p[i][4]-48)*100+(p[i][5]-48)*10+(p[i][6]-48);
		
		}
	}

	int partition(int s,int t)
	{
		int l=s;int r=t;
		q[0]=q[s];
		int x=q[s];
		while(r>l)
		{
		    while(q[r]>=x&&r>l)
			    r--;
		        q[l]=q[r];
            while(q[l]<=x&&l<r)
			    l++;
		        q[r]=q[l];
		}
		q[l]=q[0];
		return l;
	}
	void quicksort(int s,int t)
	{
		if(s<t)
		{
			int k=partition(s,t);
			quicksort(s,k-1);
			quicksort(k+1,t);
		}
	}
	void duplicate()
	{
		int i=1;
		while(i<=num-1)
		{
		    if(q[i]==q[i+1])
			{
			    while(i+count<=num&&q[i]==q[i+count])
				{
		            count++;
				}
	            dot* a=new dot;
		        a->data=q[i];
		        tps->n=a;
				tps=a;
		        dot* b=new dot;
		        b->data=count;
		        tpss->n=b;
				tpss=b;
		        i=i+count-1;
				count=1;
			}
			i++;
		}
		tps->n=NULL;
		tpss->n=NULL;
	}
	void print()
	{
		if(tps!=ps)
		{
			tps=ps->n;
		    tpss=pss->n;
		    while(tps!=NULL)
			{
			    if(tps->data/10000>=100)
				{printf("%d",(tps->data/10000));printf("-");}
				else if(tps->data/10000>=10&&tps->data/10000<100)
				{printf("0");printf("%d",(tps->data/10000));printf("-");}
				else
				{printf("00");printf("%d",(tps->data/10000));printf("-");}
				if(tps->data%10000>=1000)
				{printf("%d",tps->data%10000);printf(" ");printf("%d\n",tpss->data);}
				else if(tps->data%10000>=100&&tps->data%10000<1000)
				{printf("0");printf("%d",tps->data%10000);printf(" ");printf("%d\n",tpss->data);}
				else if(tps->data%10000>=10&&tps->data%10000<100)
				{printf("00");printf("%d",tps->data%10000);printf(" ");printf("%d\n",tpss->data);}
				else 
				{printf("000");printf("%d",tps->data%10000);printf(" ");printf("%d\n",tpss->data);}
                tps=tps->n;
			    tpss=tpss->n;
			}
		}
		else
			printf("No duplicates.\n");
	}
};
int main()
{
	while(scanf("%d",&num)!=EOF)
	{
		poj1002 p1;
	    p1.input();
	    p1.change();
	    p1.quicksort(1,num);
		//for(int i=1;i<=num;i++)
		//cout<<q[i]<<" ";
	    p1.duplicate();
	    p1.print();
	    delete []p;
	}
	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