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 whu200531130149 at 2007-02-27 22:48:32 on Problem 1002
#include <iostream>
using namespace std;
long int fix(char a[]);                                 //输入标准化的号码
void output(long int n);                                //输出号码
void sort(long int a[],long int f,long int t);          //快速排序

int main()
{
long int i,k,count,flag=0;char temp[30];
long int a[100001],*p,*q;
cin>> k;
for(i=0;i<k;i++)
  {
  cin>>temp;
  a[i]=fix(temp);
  }
a[i]=-1;                                            //电话号码簿结束标志
sort(a,0,k-1);
p=a;q=a;flag=0;
while(*p!=-1)                                       //输出电话号码簿
   {
   count=0;
   while(*p==*q)
      {
      q++;count++;
      }
   if(count>1)
   {output(*p);cout<<' '<<count<<endl;flag=1;}
   p=q;
   }
if(flag==0)cout<<"No duplicates.";
return 1;
}

long int fix(char a[])
{
char *p;long int flag,sum;
p=a;sum=0;
while(*p!='\0')
   {
   flag=0;
   switch(*p)
      {
      case 'A':case'B':case'C':
           *p=2;flag=1;break;
      case 'D':case'E':case'F':
           *p=3;flag=1;break;
      case 'G':case'H':case'I':
           *p=4;flag=1;break;
      case 'J':case'K':case'L':
           *p=5;flag=1;break;
      case 'M':case'N':case'O':
           *p=6;flag=1;break;
      case 'P':case'R':case'S':
           *p=7;flag=1;break;
      case 'T':case'U':case'V':
           *p=8;flag=1;break;
      case 'W':case'X':case'Y':
           *p=9;flag=1;break;
      case '0':case '1':case '2':case '3':case '4':
      case '5':case '6':case '7':case '8':case '9':
           *p-='0';flag=1;break;          
      }
   if(flag==1)sum=sum*10+*p;
   p++;
   }
return sum;
}

void output(long int n)                                   //标准输出电话号码 解决了首位为零的问题
{
long int j,k,t;
j=1000000;
for(k=1;k<8;k++)
{
t=(n/j)%10;
cout<<t;
if(k==3)cout<<'-';
j/=10;
}
}

void sort(long int a[],long int f,long int t)                     //快速排序应该不会有什么问题吧??
{
long int i,j,k,p;
if(t-f>1)
   {
   k=a[f];i=f;j=t;p=-1;
   while(j>i)
      if(p==1)
          {
          while(j>i&&a[i]<=k)
             i++;
          a[j]=a[i];
          p=-1;
          }
      else
          {
          while(j>i&&a[j]>=k)
             j--;
          a[i]=a[j];
          p=1;
          }
      a[i]=k;
      sort(a,f,i-1);
      sort(a,i+1,t);
   }
}

麻烦各位大虾帮帮忙看看到底出了什么问题,或者谁有比较好的测试数据留下也好,小弟多谢了~~~~


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