为啥全屏TLE?

B2120 单词的长度

syr1125 @ 2022-01-26 18:59:49

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    char a[1000];
    int n = 0, word = 0, com = 0;
    while ((a[n] = getchar()) != '\n')
    {
        if (a[n] != ' ')
        {
            word ++;
        }
        else
        {
            if (word && com)
            {
                cout << ',' << word;
            }
            else if (word)
            {
                cout << word;
                com = 1;
            }
            word = 0;
        }
    }
    if(word)
    {
        cout << ',' <<word;     
    }
    return 0;
}

by ningago @ 2022-01-26 19:19:11

@sunyiran1125

不能这样判(!= '\n\')吧,改成!= -1or!= EOF试试


by syr1125 @ 2022-01-26 20:19:26

通了,谢谢


|