看板 b99902HW 關於我們 聯絡資訊
testgirl 54題,題目在 http://palcourse.csie.ntu.edu.tw/testgirl/problem/c2007/practice/CharProcessing.htm 不知道為什麼 第 5 次試驗:你的程式當掉了!>"< 原因:使用到不該用的記憶體 沒有通過試驗。:( 實在找不出bug,請強者解惑 這是我的程式碼 #include<stdio.h> #include<string.h> int main() { //FILE *fin=fopen("input.txt","r"); char CHA[40000],com[]="COMMAND"; char now; int pos; int i,j,k,l=0; fscanf(stdin,"%*s"); fscanf(stdin,"%*c"); while(1) { fscanf(stdin,"%c",&CHA[l++]); CHA[l]='\0'; if(l>=7) if(strcmp(&CHA[l-7],com)==0) { CHA[l-7]='\0'; l-=7; break; } } while(fscanf(stdin,"%*s %d %c",&pos,&now)!=EOF) { for(i=l++;i>=pos;i--) CHA[i+1]=CHA[i]; CHA[pos]=now; } printf("%s",CHA); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.242.229
math120908:是說...他沒有規定insert指令一定要照順序輸出吧= =?? 11/27 22:56
math120908:而且這題不是要你用linked-list嗎(茶) 11/27 23:08
felixgwu:抱歉,想說要考string,先練習string的寫法 11/27 23:36
felixgwu:不照順序輸出,是什麼意思呢?抱歉,我聽不太懂 11/27 23:37
math120908:哦就是說他可能先出現insert 10 X再出現insert 1 X吧!? 11/27 23:39
math120908:咦我發現我皓呆掉了XDDD 沒事Q_Q" 11/27 23:39
math120908:好像是陣列太小的關係= =" 11/27 23:51
felixgwu:謝謝,本來想說設40000就夠的說 11/28 00:02