--- 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 %}
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up