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

help~~~~~

Posted by wolves at 2008-09-21 21:01:39 on Problem 1002
为什么老是不对啊?有高手指点一下吗
#include<iostream>
#include<cstring>
using namespace std;
const int M=10000;
int main()
{
	int i,n,j;
	char c,num[M][9];
	char *pnum[100];
	cin>>n;
	for(i=0;i<n;i++)
	{
		j=0;
		while(cin>>c)
		{
			if(c=='-'||c=='Q') continue;
			else if(c>='A'&&c<='C')	num[i][j++]='2';
			else if(c>='D'&&c<='F') num[i][j++]='3';
			else if(c>='G'&&c<='I') num[i][j++]='4';
			else if(c>='J'&&c<='L') num[i][j++]='5';
			else if(c>='M'&&c<='O') num[i][j++]='6';
			else if(c>='P'&&c<='S') num[i][j++]='7';
			else if(c>='T'&&c<='V') num[i][j++]='8';
			else if(c>='W'&&c<='Y') num[i][j++]='9';
			else if(c>='0'&&c<='9') num[i][j++]=c;
			if(j==3) num[i][j++]='-';
			if(j>7) break;
		}
		pnum[i]=num[i];
		num[i][j]='\0';
	}
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			if(strcmp(pnum[i],pnum[j])>0) swap(pnum[i],pnum[j]);
	int sum,k,flag=1;
	for(i=0;i<n;i++)
	{	
		k=i;
		sum=0;
		for(j=k+1;j<n;j++)
		{
			if(strcmp(pnum[i],pnum[j])==0)
			{
				sum++;
				flag=0;
			}
			else	{i=j-1;break;}
		}
		if(sum)
		{
			for(j=0;j<9;j++)
				cout<<pnum[k][j];
			cout<<' '<<sum+1<<endl;
		}
	}
	if(flag) cout<<"No duplicates.";
	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