--- tags: DICE C --- 17-11 自主學習 === > [name=CHAWTeam] --- 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) --- 題目 -- ```! 一直輸入字元,直到出現「GG」字樣,輸出共打了幾個字(包含「GG」)。 輸入範例: AAAAAAAAFHBFKOEEFEFGG 輸出範例: 21 ``` 程式碼 -- ```c= #include <stdio.h> int main() { int n = 0, gTimes = 0; char ch; scanf("%c", &ch); while (gTimes < 2) { if (ch == 'G') gTimes++; else if (gTimes == 1) gTimes--; n++; scanf("%c", &ch); } printf("%d\n", n); return 0; } ``` 執行 -- ```! AAAAAAAAFHBFKOEEFEFGG 21 ``` --- [查看我們在HackMD上的所有筆記](https://hackmd.io/@CHAWTeam) 目錄:[DICE C語言程式破解](https://hackmd.io/@CHAWTeam/DiceC) --- {%hackmd Iiu5mOixR7yWkPHKCkabBg %} <iframe class="LikeCoin" height="235" src="https://button.like.co/in/embed/chawteam/button?referrer=https://hackmd.io/@CHAWTeam/DiceC-17-11" width="100%"></iframe> --- {%hackmd i1nMRrZcTFmTvoF897K9zg %}