2 like 0 dislike
4.5k views
計算字數

在英文中,被空白隔開的就會算是一個單字,所以

This is a pen.

這個句子中共有4個單字,請寫一個程式,計算輸入的句子共有多少個單字

輸入說明:

輸入一個句子,輸入會以一個句點.作為結束

輸出說明:

輸出一個正整數,表示輸入的句子共有幾個單字

輸入範例:

This is a pen.

輸出範例:

4
[Exercise] Coding (C) - asked in 2017-1 程式設計(一)AD by (18k points)
ID: 33762 - Available when: Unlimited - Due to: Unlimited

edited by | 4.5k views

24 Answers

0 like 0 dislike
Hidden content!
** *** * *** ***
* * **** ** *****
int main()
{
*****   char ** ***
***** * * * * int ** *
** ***** * *****
* ** * * * * * *
* * * * ** b = ** *
**** * * while(*ptr != '.')
*** ** * *** {
* * **** * * * ** ** * * * **** * ** * * * * * ** *** * ** *
* * a++;
* ** * ** **
* * ** * ptr++;}
** * ** ** else
** * * ** * ptr++;
* * ** * ** * * *
** ** ** * *
* ** *** ** * * * = b-a;
* ** * ** ** * *
return 0;
* *
  **** *
** * **
* *
answered by (228 points)
0 0
prog.c: In function 'main':
prog.c:7:2: warning: 'gets' is deprecated [-Wdeprecated-declarations]
  gets(str);
  ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:8:5: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
  ptr=&str;
     ^
/tmp/ccSGzuxf.o: In function `main':
prog.c:(.text+0x39): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
* * ******* * ***
**** * * ** *****
int main()
{
*****   char * * ** *
** * * * * * int * *
* * * * * * * * ** *
*** * * * * ** *** * **
** * * b = * *****
** * while(*ptr != '.')
** ** * ** {
** ** ***** ** * *** ** *** ** *** * * * * ** **** * * ** * *** * * * *
** * * ** ** a++;
**** ** *** **
* * * ***** ptr++;}
* *** * * else
*** * * ***** ptr++;
**** ** * ** *
* ********** * ** *
** **** *** ** * * *** = b-a;
* * ** * * * *******
return 0;
** *** * *****
  * *
* * ***
* *
answered by (228 points)
0 0
prog.c: In function 'main':
prog.c:7:2: warning: 'gets' is deprecated [-Wdeprecated-declarations]
  gets(str);
  ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:8:5: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
  ptr=&str;
     ^
/tmp/ccDQzQ5Z.o: In function `main':
prog.c:(.text+0x39): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main(void)
{
** * * ** * **** * * *** * * ** * ** * ** * ** * last=0,cnt=0,num;
*** * * * * * ****** * ******* * ** * *** *
     {
* ** *** *** ** * * **** ** * ** *** * ** ** * input number");
* * * *** * * *** * * * * * ** * * * * **** **** * *** * * * * * * *
* * *** *** ** * * * * * * ** * ** * ** *** *
**** ** ** * * * * ** * * *** ** *****
* *** * * ** ******** * ** ** **** *** * ** * ** ** *** ***** * *** *** * ** ** * * *
*** ** * *** * * ** ** * ** * *** *** *** **
   }
* ** * * *** *** ** ****** * * * ***** ******* ** ** * * *** * * * ******* * *** * * *** ** ** * * * * *** ** **
* ****** ** *** * **** ** ** * *** * ***** * 0;
}
answered by (190 points)
0 0
prog.c: In function 'main':
prog.c:13:4: error: expected expression before '}' token
    }
    ^
prog.c:14:26: warning: format '%d' expects argument of type 'int', but argument 2 has type 'int *' [-Wformat=]
                 printf("%d\n",&num);
                          ^
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main(void)
{
**** ** * * * ** * * **** ** * ** * last=0,cnt=0,num;
       while(1)
     {
* * *** * * * *** * *** ** * *** * * ****** *** * * * * input number");
** * ****** *** * ** *** * **** **** ** ****** ** *** *** **** *** *******
** * * ** ** * * **** * **** * ***** ** ** * * * * ** *
***** **** ********* ** *** ** **** ** ** ** * ***** ****
* ** * ** * ** ** * **** ******* * * ** * * * * * * ** * * ** **** ** ******* * * * * **** **
* ** **** * **** **** * ** ** ***** *** * **
* * * * * ** * * *** ** ** ** * * *** ** **** *** ** ** ** ** * *** *** ** *****
* ***** ** * * *** * * * * ** * ***** 0;
}
answered by (190 points)
0 0
prog.c: In function 'main':
prog.c:13:17: error: too few arguments to function 'printf'
                 printf();
                 ^~~~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:364:12: note: declared here
 extern int printf (const char *__restrict __format, ...);
            ^~~~~~
prog.c:15:1: error: expected declaration or statement at end of input
 }
 ^
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
    char c;
    int count,word;
    int n,ri;
    scanf("%d", &n);
    getchar();
    for(ri = 1; ri <= n; ri++)
*** * *** * * *** *** * ** * * *
** * ** ** ****** * * * ***** * ***** ** = getchar();
** ** * ** * *** ** ** ** *** * ******* * * ** = 0;
* * ** * **** * *** ** ** ** * *** ** * * ** ** * = 0;
***** **** * * ** ****** * * ** *** ** ** * ** **** != '.')
* ** **** * ** *** ** *** ***** * ** * *** * *
** * * ******** * * ** * * * * **** ** ** * ** **** **** == ' ')
*** * * *** * * * *** * * * * * * **** ** * ***** ** **** ** *
* ***** * ** ** ** * * ** ** * *** *** * * * * * ***** * ** ** *** ***** ** ** ** == 1)
*** **** * **** * **** **** * * * ** * ** * * * ** ** *** *** * * * * ** **** *
** ** * * * ** * * ***** *** * ** *** **** ** ***** ** ******* ***** * *** ** * *** ** * **** * * * * ** * ** **** * **
* * *** * **** * *** * * ** ** * *** **** * * ** ** *** *** ** * ** **
*** * ****** * ** * *** *** ** **** **** * * ** ** ** * * ** * *** ***** * * * ** * = 0;
*** * * * ** ** * *** * *** ** * * * * * * * *
* **** *** * * ***** ** * *** ******* * ** *** *** ** *** *
* * ** * * * * *** *** * * ** ** **** *** * * * * **** ** ** **** *
* ** ** ***** * * * ** * ** * * * *** *** * * ** * ** ****** * * * *** * * = 1;
** *** ** *** *** * ** ****** * ***** ** ** ** * ** * * * * *
** * * * * ***** ** ** * ** * *** * ** * **** * * *** * ****** = getchar();
        }
** * * * *** * * * *** *** ** * ** * * * ***** == 1)
** * ** *** ***** *** ** ** ** * * * * *
** ** ** * * * * ** * ** ** ** ** ****** **** ** * **
* * ***** ** *** ** **** **** * **

****** ***** * *** * * * *** * **** *** * * * ** ** * **** * count);
    }
}
answered by (174 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
*** *** ** * * * *
****** ** *
int main() {
** ** * * ** str[20];
* * ** ******
* * *** *
****** * * *
* ** * **** ** ** {
** ** * * ***** ** * {
* ** ** * * }
****** ** * *** * * {
** ** ** * }  
** *** * ****
* *
***** ** ** * * ** *** **
*** * 0;
}
answered by (160 points)
0 0
prog.c: In function 'main':
prog.c:6:2: warning: 'gets' is deprecated [-Wdeprecated-declarations]
  gets(str);
  ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
/tmp/ccYz5ApC.o: In function `main':
prog.c:(.text+0x26): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <stddef.h>
int main()
{
        char input[100];
        int i,count,len,flag,pre;
        while(fgets(input,100,stdin)!=NULL)
        {
* ** ** * * ** ** * ** ***** * * ***** * ******* **** ********* * * * **
* * *** * ** *** ** ********* * ** * * * ** * * * ** * ** ** ** * * *** *
*** ** ** **** * ** * * ** *** * * *** * * * * ** ** ** * * * ** * * * *****
            {
*** * *** * ** * ** ** * * **** ** * *** * ** * * * * * * * ** ** ** * ****** * * * ** * * ***
** * *** ** * * *** * * * ** * * ** * ** ** * * * ** ** * ** * ** * *** *** * ** * ** ** **
* ** ** * * * * * * * *** ** * * *** **** * * *** * * * * ** * * ** * * ** *** *
* * *** ** **** ** *** * **** ** ** ** *** * * ** * ** * ****** * ** ** *** * * ** * * * **
* ****** ** * * ****** *** ** * * *** ********** * * * * *** ** * ** ** * * ***** * **** * ** * ** ** * * *** ** * ** * ** ** ** * * * * * * ****** ******** * *
* * ** ***** * *** * * ** ** * * **** ** * **** * ***** ** *** *** ** * ** * * * ***** ** * * * **** * * * *

** *** ** ** * * * ** * ***** ** * ***** * * * ** ** **** ****** * *** * * *** * ** ** ** *** * * * * * *** * * *** * * * ** **
*** *** ** * *** ** ** ** **** * ** * * ** *** * **** * * ***** ** * * * * ** ** *** ** * * * **** ** ** * * ** *** * * * * *** * * ** * ****
**** * * ** ** *** **** *** * **** ** *** * * ******** ** ** * * * ** ** * ** * * * *** ** **** * * ** * * *** *** * **** *** *** * *
* * ** * **** ** * * * ** **** * **** * **** *** **** **** * ** * * * **** * *** ** ** ** * *** * ** **** ** ** *** * **** * * * ***** ** * * * * * * **
* *** * *** ***** **** **** ** * * **** ***** ** *** ** ****** *** * ** * * * ** * *** ** *** ***** ** ** * * * * **** * *
** * ** * * ** ** ** * ** * * ****** * * * *** ***** ** *** * * *** ** * ****** ** ** * * ** * * ** * * **** * * * **** * * * *** *** * ** * * **




*** *** * * * ********** *** ** * ** * *** * * * ** * ** * *** * ** * **** *** * * * * * **
*** * * * **** * **** * * * *** * *** **** ********* **** * * * ** * *** * * * ** **** * *** * * *
** * ** *** * * *** ** *** * ** * **** * ******* * *** * * ** * ***** *** * ** * *******
* * * *** ** **** * * * ** ** * *** * * * ** ***** * ** ** * ** ** * ** * * * *** ** ****** * ** * *** * * * ** **** * *
** ** * * * ** * * *** ** * * * * *** ** * ** *** ** * *** *** ** * * ** * ** ****** * ** *

* * ** *** * * * * * * ** *** ** ** * * ** ** * **** * * ** *** * *** ** ***
            }

            printf("%d",count);
        }






    return 0;
}
answered
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <stddef.h>
int main()
{
        char input[100];
        int i,count,len;
        while(fgets(input,100,stdin)!=NULL)
        {
*** * ** ** ** * * ** * *** ** * * ** ** ** ** * * ** *** ** * * * *
** * * ****** ** *** ** *** ** * **** * ****** **** * ***
*** * ** **** ** ***** ***** * **** ** * ** ** * * ** *** ** * * * *** ***
* * * ** * * ** ** * ** * * * **** * **** * **** * *
***** * * **** ** * ** * * * * *** * * *** ** ***** * ** *** * ** **** * ***** ** * *** * * **** ** ***
*** * ** ** ****** * * * ** * * *** * ** * * * ** ** * * ** * * ** ** * * *** * ** * * *
**** * **************** ** * ** * ** ** * * * ** * ** ** * * * * * * * ** **** ** **** * * ***** ******* * ** ** *** ** * **** ****** ** *** * * ** ** * *** * * *
* ***** * ** ** * ** ** ** * ** * * ** *** * * * * * * ****** *** * * ***** * ****** *** ** ** *

**** ** * * * *** **** **** ** ******* * * * * ***** * ** * ** * ** * *** ** **** * *** * **** * *** **** * *** * **** * * * ** *
***** * ** * * * * **** * * *** *** ** *** *** ** * * * * * **** * * ******* ** * ** * ** ** ** * ** * *** *** ** ********* ****** *** ** ** * ** ***
* * **** * **** * * * * * ** ** *** ***** **** *** * ** ** ******* ** * ** **** **
* * * ** * * ** * * ** *** * * * ** *** * ** *** * * ** * * * * ** * ** ** ** * ** * ** * **
* * ** * ** * * * ** ** ******* ** ** * ***** ** *** * * * ** * * *** * ** * * * *** * *
** * * * ***** ** * * *** **** ** * * * **** * * ** * ****** * * * * *** *** ** * * * *** ** ** **** * * * ****** *** ***
* * ** * *** * * * *** * * * **** ** * ****** *** ** **** * ** ** ** ** * * ** * * **** **

* ** * * * ** * *** ** * ****** * ** * *** **** ** * * ** * * * ** **** * * * *
* * * ** * * * **** *** * * *** *** * ** * ** * **** *** * ***

            printf("%d",count);
        }






    return 0;
}
answered
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <stddef.h>
int main()
{
        char input[100];
        int i,count,len;
        while(fgets(input,100,stdin)!=NULL)
        {
*** * * * **** ** * * ****** * ** * ** **** ******** * *** * *** *
* *** * * ** ** * ** ** * * *** * * * * **** ** ** * * * * * **
** * * * ****** * * * * ** ********* ** * * ** * ** *** * *** * * **** *** **** ** ** * ** * ****
* * * * ***** * ** * * * * ***** * * *** ** * *** **** * *** ** *
* * **** ** * * * **** *** * * ** * * * * * * ** * ***** **** ***** ** * **** * ** ** * ******** ** *** ** ** *** ** * *** * * * * ***** * *** * **** ** ****** * * * * ** ** **
* ** *** **** * * * * ** ** * * ****** * *** ** * *** * * * **** * * ** * * * ** * * * * *

** ** ** ** * *** ** ***** *** * * ** *** **** ** *** * *** ** * ** ******** *** * ****** * * ** ** * * ** **** * * * * *** * ******
** * *** ** * * ** ** * * * * * * * * * * ** ** ** * * ** * ** * * ** * * ****** *** **** * * ** * * ** * * ****** * * ***** * ***** ** * *** *** ** * * * *** ** *
* * * * ** ***** * ** ** * ** *** ***** * ** *** **** ** ***** *** * **** *** ** * * *** **
** ** * * *** * * * * * * *** ** ** ** *** ** * ***** * * ** * ** ***** * *** ** * * **** * *** *** * *
* *** * *** **** ***** * ** *** * *** ** * ** ** *** * *** ** * **** * * *** ** * * **** *
* * * ** * ** * * *** * *** * * *** ** *** * ** * * ** * ***** ** ** ** * ** ** * *** *** * ******* * **** * ** * ***
** ***** * ***** ** * ** * * ***** * * * ** *** **** ** ** ** * * * * * * * * ** * ***** * *** ***** ** * ** ** ** * * ** * *
** * ** * *** *** ** ** * *** * * * * * ** * * * * ** *** * * * * **** * ** *** ** * * ** ** *

* ** ** * ** ** * *** ** ** ***** ** **** * * ** ***** *** * * * *** ** ** * ******* * *****
            printf("%d",count);
        }






    return 0;
}
answered
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
***** * *** * * * * ** *** ** * ** * * ** ** input[100];
        int i,count,len;
*** * * ** * * * * * *** * ** ****** * ** * ** *

* *** * * * * * **** * * ** * ****** *** * * ** *** *** * * * * ***
*** ****** ** * * ***** * * * ** ** * * ** *** * * ****** *
* * * * *** * * * * * * *** ** *** *   count=1;
* **** * * * * *** ** * ** * * * * ****** * * * * * * * ***** ** * ** ** * **
* * * * * * * * * * ******* * * * * * * ** **** **** ******** ****
*** ** * ** *** ** * * ** * ** ** *** *** **** * ** * * ** ** * ** * *** * ** **** ** ** * ** * *** ** ***
*** * * * **** **** **** * ** ** * * ** * * * ** * **** ** * ** *** ** * * * **** * * *** *** * ** ** **
*** **** *** * * * * ** * ***** * ** **** *** * *** * *** ** * *
            ** ********* * ** ** * * **







    return 0;
}
answered
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.59.123
©2016-2025

Related questions

3 like 0 dislike
20 answers
[Exercise] Coding (C) - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 33758 - Available when: Unlimited - Due to: Unlimited
| 4.1k views
3 like 0 dislike
22 answers
[Exercise] Coding (C) - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 33757 - Available when: Unlimited - Due to: Unlimited
| 5.4k views
3 like 0 dislike
9 answers
[Exercise] True/False - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 33763 - Available when: 2017-11-16 14:00 - Due to: 2017-11-16 14:30
| 900 views
3 like 0 dislike
6 answers
[Exercise] Coding (C) - asked Nov 30, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 34979 - Available when: Unlimited - Due to: Unlimited
| 1.6k views
3 like 0 dislike
5 answers
[Exercise] Coding (C) - asked Nov 30, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 34978 - Available when: Unlimited - Due to: Unlimited
| 1.7k views
12,783 questions
183,442 answers
172,219 comments
4,824 users