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 xj_nan at 2009-05-13 19:32:32 on Problem 1002
#include <iostream>
#include <set>
#include <string>
using namespace std;
void translate(char a[100],char b[100])
{
	int i=0,j=0;
	while(a[i]!='\0')
	{
		switch(a[i])
		{
		case 'A':
		case 'B':
		case 'C':
		case 'a':
		case 'b':
		case 'c':
			b[j]='2';
			i++;
			j++;
			break;
		case 'D':
		case 'E':
		case 'F':
		case 'd':
		case 'e':
		case 'f':
			b[j]='3';
			i++;
			j++;
			break;
		case 'G':
		case 'H':
		case 'I':
		case 'g':
		case 'h':
		case 'i':
			b[j]='4';
			i++;
			j++;
			break;
		case 'J':
		case 'K':
		case 'L':
		case 'j':
		case 'k':
		case 'l':
			b[j]='5';
			i++;
			j++;
			break;
		case 'M':
		case 'N': 
		case 'O':
		case 'm':
		case 'n':
		case 'o':
			b[j]='6';
			i++;
			j++;
			break;
		case 'P':
		case 'R':
		case 'S':
		case 'p':
		case 'r':
		case 's':
			b[j]='7';
			i++;
			j++;
			break;
		case 'T':
		case 'U':
		case 'V':
		case 't':
		case 'u':
		case 'v':
			b[j]='8';
			i++;
			j++;
			break;
		case 'W':
		case 'X':
		case 'Y':
		case 'w':
		case 'x':
		case 'y':
			b[j]='9';
			i++;
			j++;
			break;
		case '-':
			i++;
			break;
		default:
			b[j]=a[i];
			i++;
			j++;
		}
	}
	b[j+1]='\0';
}
typedef struct mystruct
{
	string y;
};

			
int main()
{	
	char a[100],b[100];
	mystruct c[100];
	int count=0,i=0,j=0,t,z,x,d[10000]={0},flag=0;
	typedef set<string> SetChar;
	SetChar coll,coll1;
	cin>>count;
	t=count;
	while(count--)
	{
		for(i=0;i<100;i++)
		{
			b[i]='\0';
			a[i]='\0';
		}
		scanf("%s",a);
		translate(a,b);
		c[j].y=b;
		j++;
		coll.insert(b);
	}
	SetChar::iterator pos;
	x=0;
	for(pos=coll.begin();pos!=coll.end();++pos)
	{
		for(z=0;z<t;z++)
			if(*pos==c[z].y)
			{
				if(d[x]>0)
				{
					coll1.insert(*pos);
					flag=1;
				}
				d[x]++;
			}
		x++;
	}
	i=0;
	string s;
	if(flag==1)
	{
		for(pos=coll1.begin();pos!=coll1.end();++pos)
		{
			s=*pos;
			if(s.size()>3)
				s.insert(3,"-");
			cout<<s<<' ';
			while(d[i]<=1)
				i++;
			printf("%d\n",d[i]);
			i++;
		}
	}
	else
	{
		printf("No duplicates.\n");
	}
	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