#890: TLE+1


tobbymailbox (Toby)


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

int main () {
    char str [99999];
    while (gets(str)!=EOF) {
        int w=0,x;
        int len = strlen(str);
        for (x=-1; x<=len;x++) {
            if (str[x]==32) {
                w=w+1;
            }
        }
        printf ("%d\n",w);
    }
    return 0;
}

 

不知道為什麼一直過不了 試了一整個晚上。。。

 

#894: Re:TLE+1


shik (shik)


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

int main () {
    char str [99999];
    while (gets(str)!=EOF) {
        int w=0,x;
        int len = strlen(str);
        for (x=-1; x<=len;x++) {
            if (str[x]==32) {
                w=w+1;
            }
        }
        printf ("%d\n",w);
    }
    return 0;
}

 

不知道為什麼一直過不了 試了一整個晚上。。。

 

!= EOF 刪掉

#896: Re:TLE+1


s864372002 (建資98級鋼琴)


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

int main () {
    char str [99999];
    while (gets(str)!=EOF) {
        int w=0,x;
        int len = strlen(str);
        for (x=-1; x<=len;x++) {
            if (str[x]==32) {
                w=w+1;
            }
        }
        printf ("%d\n",w);
    }
    return 0;
}

 

不知道為什麼一直過不了 試了一整個晚上。。。

 

!= EOF 刪掉 


gets()在讀到檔尾時回傳的是0而不是EOF喔,!=EOF這樣會造成無窮迴圈XP