pku acm里面的第1002题,不知道我的程序为什么能不过?
// 1002.cpp : 定义控制台应用程序的入口点。//
#include "stdafx.h"
#include <math.h>
#include <iostream>
using namespace std;
typedef struct HM
{
int num,number;
HM *r,*l;
} hm;
int tans(char);
void inselt(int,hm *&);
void ouselt(hm*,int&);
hm* creathm(int);
int main ()
{
int count,a[7],b;
int m=0;
hm *s;
hm *gen=new hm;
gen->num =0;
gen->r =0;
gen->l =0;
gen->number=0;
char c[50];
cin>>count;
for (int i=0;i<count;i++)
{
cin>>c;
int aa=0;
for(int j=0;c[j]!=NULL;j++)
{
if(tans(c[j])!=10)
{
a[aa]=tans(c[j]);
aa++;
}
}
b=0;
for(int k=0;k<7;k++)
{
int df=pow(10.0,(6-k));
b=b+a[k]*df;
}
if (gen->number ==0)
{
gen->number =b;
gen->num ++;
}
else
{
s=gen;
inselt(b,s);
}
}
hm* g=gen;
ouselt(g,m);
if (m==0)
cout<<"No duplicates."<<endl;
return 0;
}
int tans(char d)
{
if(d-'0'>=0 && d-'9'<=0)
return d-'0';
switch(d)
{
case 'A':
case 'B':
case 'C': return 2;
break;
case 'D':
case 'E':
case 'F': return 3;
break;
case 'G':
case 'H':
case 'I': return 4;
break;
case 'J':
case 'K':
case 'L': return 5;
break;
case 'M':
case 'N':
case 'O': return 6;
break;
case 'P':
case 'R':
case 'S': return 7;
break;
case 'T':
case 'U':
case 'V': return 8;
break;
case 'W':
case 'X':
case 'Y': return 9;
break;
default : return 10;
}
}
hm* creathm(int a)
{
hm *b=new hm;
b->number=a;
b->l =0;
b->r =0;
b->num =1;
return b;
}
void inselt(int t,hm *&s)
{
while(s!=0)
{
if( t< s->number)
{
if(s->l==0)
{
s->l=creathm(t);
s=0;
}
else
s=s->l;
}
else if ( t> s->number)
{
if(s->r==0)
{
s->r=creathm(t);
s=0;
}
else
s=s->r;
}
else
{
s->num++;
s=0;
}
}
}
void ouselt(hm *s,int &m)
{
if(s!=0)
{
ouselt(s->l,m);
if(s->num >1)
{
m++;
char rf[10];
_itoa( s->number, rf, 10);
char sh[10];
for (int ii=0;ii<3;ii++)
sh[ii]=rf[ii];
for (int jj=3;jj<8;jj++)
sh[jj+1]=rf[jj];
sh[3]='-';
cout<<sh<<" "<<s->num <<endl;
}
ouselt(s->r,m);
}
}