#4183: 自己測沒有問題


ChengFuLin (TofuLin)

學校 : 國立臺灣海洋大學
編號 : 11341
來源 : [218.167.128.14]
最後登入時間 :
2010-09-15 20:38:12
a009. 解碼器 -- ACM 458 | From: [218.160.155.168] | 發表日期 : 2010-08-31 16:52

我用Visual C++ 2005

自己測試時並沒有問題

 但是上傳後卻一直出現RE的錯誤

 

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define Code 7

struct Input{

 char *text;
 struct Input *link;

};

struct Input* getNode(void);

void Print_text(struct Input *);

void subtract_Code(int code, char *Str);


int main(void){

 char *input;
 struct Input *Input_Node = NULL;
 struct Input **Now;

 input = (char *) malloc(sizeof(char *));

 Now = (struct Input **) malloc(sizeof(struct Input *));

 for(Now = &Input_Node; gets(input) != NULL; Now = &((*Now)->link)){
  
  *Now = getNode();

  strcpy((*Now)->text, input);

  subtract_Code(Code, (*Now)->text);
 
 }

 Print_text(Input_Node);


 return 0;

}

struct Input* getNode(void){

 struct Input *temp;

 temp = (struct Input *) malloc(sizeof(struct Input));

 temp->text = (char *) malloc(sizeof(char *));

 temp->link = NULL;

 return temp;

}

void subtract_Code(int code, char *Str){

 int len = strlen(Str);
 int i;

 for(i = 0; i < len; ++i){
 
  Str[i] = Str[i] - code;
 
 }

}


void Print_text(struct Input *Now){

 for(; Now != NULL; Now = Now->link){
 
  puts(Now->text);
 
 }

}

 
#4184: Re:自己測沒有問題


ChengFuLin (TofuLin)

學校 : 國立臺灣海洋大學
編號 : 11341
來源 : [218.167.128.14]
最後登入時間 :
2010-09-15 20:38:12
a009. 解碼器 -- ACM 458 | From: [218.160.155.168] | 發表日期 : 2010-08-31 17:27

 

 我改了程式如下

簡單多...又對了=.=

我一直以為這裡的程式多測資

是指

一次輸完所有資料後

再輸出...

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define Code 7


void subtract_Code(int code, char *Str);


int main(void){

 char *input;


 input = (char *) malloc(sizeof(char *));


 while(scanf("%s", input) != EOF){
 
  subtract_Code(Code, input);

  printf("%s\n", input);
 
 }


 return 0;

}

void subtract_Code(int code, char *Str){

 int len = strlen(Str);
 int i;

 for(i = 0; i < len; ++i){
 
  Str[i] = Str[i] - code;
 
 }

}

 
ZeroJudge Forum