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 wenzheng137 at 2008-08-24 18:03:04 on Problem 1002
#include<stdio.h>
#include<ctype.h>
#include<list>
#include<queue>
using namespace std;


typedef struct phone{
	int fir;
	int sec;
	int sum;
	struct phone *next;
}PNode,*Plist;


int main(){
	int num,n=0,flag=0;
	char ch;
	Plist pl,head=NULL,p,q;

	scanf("%d",&num);
	getchar();
		while((ch=getchar())!=EOF&&num>0){
			switch (ch){
			case '0':
				n=n*10+0;
				break;
			case '1':
				n=n*10+1;
				break;
			case 'A':case 'B':case 'C':case '2':
				n=n*10+2;
				break;
			case 'D':case 'E':case 'F':case '3':
				n=n*10+3;
				break;
			case 'G':case 'H':case 'I':case '4':
				n=n*10+4;
				break;
			case 'J':case 'K':case 'L':case '5':
				n=n*10+5;
				break;
			case 'M':case 'N':case 'O':case '6':
				n=n*10+6;
				break;
			case 'P':case 'R':case 'S':case '7':
				n=n*10+7;
				break;
			case 'T':case 'U':case 'V':case '8':
				n=n*10+8;
				break;
			case 'W':case 'X':case 'Y':case '9':
				n=n*10+9;
				break;
			default:
				break;
			}//switch
			if(n>=100&&flag==0){
				pl = new PNode;
				pl->next=NULL;
				pl->sec=0;
				pl->sum=1;
				flag = 1;
				pl->fir = n;
				n = 0;
			}
			if(n>=1000&&flag==1){
				num--;
				pl->sec = n;
				flag = 0;
				n = 0;
				if(head==NULL){
					head=pl;
					p=pl;
					continue;
				}
				if(head!=NULL){
					for(q=head;q->next!=NULL;q=q->next){
						if(q->fir==pl->fir&&q->sec==pl->sec){
							q->sum++;
							break;
						}
						if(pl->fir<head->fir||(pl->fir==head->fir&&pl->sec<head->sec)){
							pl->next=head;
							head=pl;
							break;
						}
						if(pl->fir<q->next->fir||(pl->fir==q->next->fir&&pl->sec<q->next->sec)){
							pl->next=q->next;
							q->next=pl;
							break;
						}
					}
					if(q->next==NULL&&(q->fir==pl->fir&&q->sec==pl->sec)){
						q->sum++;
					}
					if(q->next==NULL&&((pl->fir==q->fir&&pl->sec>q->sec)||pl->fir>q->fir)){
							q->next=pl;
					}
				}
			}//IF
		}//while
	q=head;
	flag = 0;
	while(q!=NULL){
		if(q->sum!=1){
			printf("%d-%d %d\n",q->fir,q->sec,q->sum);
			flag=1;
		}
		q=q->next;
	}
	if(flag==0)
		printf("No duplicates.\n");
}

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