看板 C_and_CPP 關於我們 聯絡資訊
下面是我做的兩種做法 第一種AC 第二種WA 不過我一直找不出來第二種錯在哪裡XD 有哪個測資是兩個做法會有不同的地方 請各位高手幫幫忙 謝謝 int main() { char str[400]; register int i,len,count; while(gets(str)) { len=strlen(str); if(len==0) return 0; count=0; for(i=0;i<len;i++) { if( (isalpha(str[i])) && !(isalpha(str[i+1])) ) count++; } printf("%d\n",count); } } ================================================ int main() { register int count=0; register char c; while(c=getchar()) { if(isalpha(c)) { while(c=getchar()) { if(isalpha(c)) continue; else break; } count++; } if(c=='\n') { printf("%d\n",count); count=0; continue; } if(c==EOF) { printf("%d",count); return 0; } } return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.164.107.205
ledia:差滿多的, 第一個只看相鄰兩個字元的對應關係 02/09 20:49
ledia:呃... 忘了上面的推文 ._. 02/09 20:52
ledia:問題應該在, 進入 isalpha 之後, 如果下一個非 alpha 就是換 02/09 20:53
ledia:行, 那就會少 output 結果 02/09 20:53
ledia:也不對 ._. 02/09 20:53
DJWS:if (c==EOF) 那段砍掉應該就會對了? 02/09 21:28
sa072686:if (c==EOF) 那邊的 printf() 沒有換行? 02/09 21:37
fjm31714:TLE沒有結束條件 02/09 21:41
fjm31714:換行也一樣WA 02/09 21:50
DJWS:那就試著把if (c==EOF)那行裡面的printf砍掉? 02/09 22:08
fjm31714:這樣最後一行的輸出勒?還是ACM每行輸出完會enter? 02/09 22:19
QQting:EOF了為啥還要輸出? 02/09 23:07
fjm31714:大概了解意思我試試看 02/09 23:23
fjm31714:恩恩是那裡沒錯 謝謝 對線上測試的方法又多了解一點了 02/09 23:25