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 atyuwen at 2007-03-17 14:22:41 on Problem 1002
#include <iostream.h>
#include <algorithm>
#include <iomanip.h> 
#include <stdlib.h>
const int LONG=15,SHORT=7;

bool compare(int a,int b)
{
	return a<b;
}

void main()
{  
	int num,i,j,count,flag=1;
	char  list[90],teml[LONG],tems[SHORT];
    for(i='0';i<='9';i++) list[i]=i;
    for(i='A';i<='O';i++) list[i]=(i-'A')/3+'2';
	for(i='Q';i<='Y';i++) list[i]=(i-'Q')/3+'7'; list['P']=list['Q'];    
	cin>>num;
	int * tel=new int[num];
	for(i=0;i<num;i++)
	{   
		char *ori=tems;
		cin>>teml;
		for(int j=0;teml[j];j++)
			if(teml[j]!=45) *ori++=list[teml[j]];            //'-'=45
		tel[i]=atoi(tems);
	}
	std::sort(tel,tel+num,compare);

	for(i=0;i<num;)             //output. follow a teacher's example;
 	{
 		count=1;
 		for(j=i+1;j<num&&tel[j]==tel[i];j++)	count++;
 		if(count>1)
 		{
 			flag=0;
 			cout<<setfill('0')<<setw(3)<<tel[i]/10000<<"-"<<setfill('0')<<setw(4)<<tel[i]%10000<<" "<<count<<endl;
 		}
 		i=j;
 	}
 	if(flag) cout<<"No duplicates."<<endl;
 	delete[]tel;
}   

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