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 19881110 at 2009-07-31 14:36:24 on Problem 1002
#include<stdio.h>
#include<string.h>

void main()
{
  char telephone1[20][16],telephone[20][9]={""};
  char str[9],ch;
  int i,j,k,m,n=0,b,a[20]={0};
  
  printf("Input the number of telephone number you wanted:\n");
  scanf("%d",&b);
  fflush(stdin);
  for(i=0;i<b;i++)
	gets(telephone1[i]);
  
  for(i=0;i<b;i++)
  {
	for(k=0,j=0;k<8;j++)
	{ 
	  if(k==3)
	    str[k++]='-';
	  ch=telephone1[i][j];
	  switch(ch)
	  {
	  case '0': str[k++]='0'; break;  
	  case '1': str[k++]='1'; break; 
	  case '2': 
	  case 'A':  
	  case 'B': 
	  case 'C': str[k++]='2'; break;
	  case '3': 
	  case 'D':  
	  case 'E':
	  case 'F': str[k++]='3'; break;
	  case '4': 
	  case 'G': 
	  case 'H': 
	  case 'I': str[k++]='4'; break; 
	  case '5': 
	  case 'J': 
	  case 'K': 
	  case 'L': str[k++]='5'; break; 
	  case '6':
	  case 'M': 
	  case 'N': 
	  case 'O': str[k++]='6'; break;  
	  case '7':
	  case 'P': 
	  case 'R': 
	  case 'S': str[k++]='7'; break;
	  case '8': 
	  case 'T': 
	  case 'U':  
	  case 'V': str[k++]='8'; break; 
	  case '9': 
	  case 'W': 
	  case 'X': 
	  case 'Y': str[k++]='9'; break;
	  default : break;
	  }
	}
	  str[8]='\0';
	 // printf("%s ",str);
	  for(m=0;m<=i;m++)
	    if(strcmp(telephone[m],str)==0)
		{
		  a[m]++;
		  break;
		}
		
		if(m>i)
		{
		  strcpy(telephone[n],str);
		  a[n++]=1;
		}
}
  for(i=0,n=0;a[i]!=0;i++)
	if(a[i]>1)
	{
      strcpy(telephone[n],telephone[i]);
	  a[n++]=a[i];
	}
  
  for(i=0;i<n-1;i++)
	  for(j=i+1;j<n;j++)
		if(strcmp(telephone[i],telephone[j])>0)
		{
		  strcpy(str,telephone[i]);
		  strcpy(telephone[i],telephone[j]);
		  strcpy(telephone[j],str);
		  b=a[i];
		  a[i]=a[j];
		  a[j]=b;
		}
  
  for(i=0;i<n;i++)
	printf("%s %d\n",telephone[i],a[i]);
}

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