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

为什么这道题用流和string就ce用char就过了……

Posted by Lostineden at 2016-09-20 16:12:17 on Problem 1002
#include<cstdio>
#include<cstring>
int tel[10];
struct Astr
{
 int flag,num;
 Astr *next[10]; 
}map,*now,*p;
int N;
int pflag=0;
char  s[50];
char c;
int change(char a)
{
  if('0'<=a&&a<='9') return a-'0';	
  if('A'<=a&&a<='P') return (a-'A')/3+2;
  if('R'<=a&&a<='Y') return (a-'A'-1)/3+2;
  return -1;
}
void getin(char s[])
{char c;
  int l=strlen(s),num=0;
  for(int i=0;i<l;i++)
     {
	   c=s[i];
       num=change(c);
	 
       if(num!=-1)
        {
	    	if(now->next[num]==NULL)
	       	  { 
				p=new(Astr);
				p->flag=1;p->num=0;
				for(int i=0;i<=9;i++)p->next[i]=NULL;
				now->next[num]=p;
			   } 
	        now=now->next[num];
	 	}
	 }
  now->num++;
}

void dfs(Astr *now,int number)
{
  if(number==7&&now->num>1)
  {
    for(int i=1;i<=3;i++)printf("%d",tel[i]);
    printf("-");
	for(int i=4;i<=7;i++)printf("%d",tel[i]);
	printf(" ");
	printf("%d\n",now->num);	
	pflag=1;  
    return;
  }//print
  
  for(int i=0;i<=9;i++)
  if(now->next[i]!=NULL) 
    {tel[++tel[0]]=i;
	 dfs(now->next[i],number+1);
	 tel[0]--;}
}
int main()
{
  scanf("%d",&N);
  map.flag=1;map.num=0;for(int i=0;i<=9;i++)map.next[i]=NULL;
  memset(tel,0,sizeof(tel));
  while(N--)
  {
    scanf("%s",s);
    now=&map;
    getin(s);
  }
  now=&map;
  tel[0]=0;
  pflag=0;
  dfs(now,0);
  if(!pflag) printf("No duplicates.\n");
  return 1;
}

之前用的string就错了 char[]就过了

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