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

C语言,本地正确,帮忙看下为什么WRONG.......

Posted by liangbo92 at 2013-04-14 20:06:44 on Problem 1051
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct KEY
{
  int size;
  char ch1[5],ch2;
}key[30];
void KEYF();
void main()
{
  int n,i,j=0,m,k=0,km,a[200],t,NUM=1;
  char *c=malloc(5),*str1=malloc(200*sizeof(char)),*str2=malloc(1000*sizeof(char));
  KEYF();
  scanf("%d",&n);
  while(n--)
  {  
     k=0,km=0,i=0;
	 fflush(stdin);
     scanf("%s",str1);
     while(*(str1+i)!='\0')                              
	 {
	    m=0;
	    for(j=0;j<30;j++)
	    if(key[j].ch2==*(str1+i)) break;
		while(m<key[j].size) *(str2+k++)=key[j].ch1[m++];    
		a[km++]=key[j].size;
		i++;
     } 
	 *(str2+k)='\0';
     for(i=0;i<km/2;i++)
	 t=a[i],a[i]=a[km-i-1],a[km-i-1]=t;
	 k=0;
	 printf("%d: ",NUM++);
	 for(i=0;i<km;i++)
	 {
	   for(j=0;j<a[i];j++)   
	   *(c+j)=*(str2+k++);
	   *(c+j)='\0';
	   for(j=0;j<30;j++)
	   if(!strcmp(c,key[j].ch1))
       printf("%c",key[j].ch2);
	 }
	 printf("\n");
   }
}
void KEYF()
{
  int i,j=0,k;
  char *str=".- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. ..-- .-.- ---. ---- ";
  key[26].ch2='_',key[27].ch2=',',key[28].ch2='.',key[29].ch2='?';
  for(i=0;i<=25;i++) 
  key[i].ch2=65+i;
  i=0;
  while(*(str+j)!='\0')
  {
    k=0;
	while(*(str+j)!=' ')
    {
	  key[i].ch1[k]=*(str+j);
	  j++,k++; 
	}
	key[i].ch1[k]='\0';
	key[i].size=k;
	j++,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