Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 计算输入行中的字数。其中单词只是一致性,第一个字符是唯一的字母_C_Count - Fatal编程技术网

C 计算输入行中的字数。其中单词只是一致性,第一个字符是唯一的字母

C 计算输入行中的字数。其中单词只是一致性,第一个字符是唯一的字母,c,count,C,Count,精确公式: 编写一个程序,计算输入行中的字数。在word中表示一致性,其中第一个字符必须是字母 输入和输出示例: 输入:1 2 2 3 输出:2 输入:123456 输出:5 输入:789878moer及更多 输出:2 输入:类似8this输出:2 节目: #include <stdio.h> #define YES 1 #define NO 0 int main() { int c, nw, inword, first_char;

精确公式: 编写一个程序,计算输入行中的字数。在word中表示一致性,其中第一个字符必须是字母

输入和输出示例:

输入:
1 2 2 3
输出:
2

输入:
123456
输出:
5

输入:
789878moer及更多
输出:
2

输入:
类似8this
输出:
2

节目:

#include <stdio.h>
#define YES 1
#define NO 0

int main() {                   
    int c, nw, inword, first_char;  
    inword = first_char = NO;  
    nw = 0;                    

    while((c = getchar()) != EOF) { 
        if (c == ' ' || c == '\n' || c == '\t') {
            inword = first_char = NO;
        } else if (inword == NO && first_char == NO) {
            if ((65 < c && c < 90) || (97 < c && c < 122)) { 
                ++nw;          
                inword = YES;  
            } else {           
                first_char = YES;               
            }                  
        }
    }

    printf("%d\n", nw);
}
#包括
#定义是1
#定义0
int main(){
int c,nw,inword,第一个字符;
inword=first_char=NO;
nw=0;
而((c=getchar())!=EOF){
如果(c=''| | c='\n'| | c='\t'){
inword=first_char=NO;
}else if(inword==NO&&first\u char==NO){
如果((65
答复:

  • 这是正确的解决方案吗
  • 有可能以更优雅的方式决定这项任务吗?如果是,如何进行
  • 这是正确的解决方案吗

    我测试了几个案例,我觉得还可以

    有可能以更优雅的方式决定这项任务吗?如果是,如何进行

    下一行

    if((65 < c && c < 90) || (97 < c && c < 122)) 
    

    我投票结束这个问题,因为它主要是基于观点的。因为这个解决方案对您有效,所以它是正确的解决方案。也许有更优雅的方式,但对谁来说更优雅?谁来决定?这将创建一个基于其他人意见的讨论,而不是解决任何地方都不存在的问题。另一次,在发布任何问题之前,请阅读您将要放置的标签的描述。关于
    word
    kernighan和ritchie
    序列
    没有任何内容,下次只需参考第页。请不要要求贡献者测试和验证您的应用。@Martin James OK。如果是这样的话,我不能问这些问题,我在哪里可以这样做?你能告诉我这个资源吗?
    if (isalpha(c))