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

1002 哪位牛帮我看看哪种情况没考虑?谢谢了!!!

Posted by tcltsh at 2008-12-16 10:12:51 on Problem 1002
#include "stdio.h"
#include "stdlib.h"
#define MAX 100

int flag;

typedef struct oo
{
  long int s,num;
  struct oo *lc,*rc;        
} tree;

long change(char a[])
{
  long n=0;
  int i=0;
  while(a[i]!='\0')
  {
    if(a[i]>='0'&&a[i]<='9')
      n=n*10+a[i]-'0';
    else if(a[i]>='A'&&a[i]<='Z'&&a[i]!='Q'&&a[i]!='Z'||a[i]>='a'&&a[i]<='z')
    {
      switch(a[i])
      {
        case 'A':case 'B':case 'C':case 'a':case 'b':case 'c': n=n*10+2; break; 
        case 'D':case 'E':case 'F':case 'd':case 'e':case 'f': n=n*10+3; break; 
        case 'G':case 'H':case 'I':case 'g':case 'h':case 'i': n=n*10+4; break; 
        case 'J':case 'K':case 'L':case 'j':case 'k':case 'l': n=n*10+5; break; 
        case 'M':case 'N':case 'O':case 'm':case 'n':case 'o': n=n*10+6; break; 
        case 'P':case 'R':case 'S':case 'p':case 'r':case 's': n=n*10+7; break; 
        case 'T':case 'U':case 'V':case 't':case 'u':case 'v': n=n*10+8; break; 
        case 'W':case 'X':case 'Y':case 'w':case 'x':case 'y': n=n*10+9;      
      }     
    } 
    i++;               
  }
  return n;   
}

tree *creat_tree(tree *p,long a)
{
  if(p)
  {
    if(p->s>a)
      p->lc=creat_tree(p->lc,a);
    else if(p->s<a)
      p->rc=creat_tree(p->rc,a);
    else
      p->num++;
    return p;
  }
  else
  {
    p=(tree *)malloc(sizeof(tree));
    p->num=1;
    p->s=a;
    p->lc=NULL;
    p->rc=NULL;
    return p;
  }
}

void zhongxu(tree *p)
{
  if(p)
  {
    zhongxu(p->lc);
    if(p->num>=2)
    {
      printf("%ld-%ld %ld\n",p->s/10000,p->s%10000,p->num);
      flag=1;
    }
    zhongxu(p->rc);
  }
}

int main()
{
  long n,i,k;
  char a,b[MAX];
  tree *root;
  scanf("%d",&n); scanf("%c",&a);
  root=NULL;
  for(i=0;i<n;i++)
  {
    gets(b);
    k=change(b);
    root=creat_tree(root,k);
  }
  flag=0;
  zhongxu(root);
  if(!flag)
    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