2 like 0 dislike
2.7k 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 | 2.7k views

24 Answers

0 like 0 dislike
Hidden content!
#include ** ** ** ***
#include * *** ** * **
#include * * **** *


int main()
{
*** *   int n;
** * ****   int i,k,len;
****   char ** ** * * * *** * ** * * * * **** ** * ** * ** ** ****
*** *   char *p;
*   int *** * *** ***
*** * **   **** ** * * ** * *
***   {
**       **** *
* * *       ***********
* *       * * * *
** **       ** ****
* *** *** ** ** *** **** ** * * * * * **** ***
* * * ***** *** *** ***** * * * * * ** * * * ** * ********* * **
****** * ** * ** *** * * * * * * * *** * * * * ***** * * * {
** ****** ** * * * ** * * * * *** ** *** *** * * *       **** *** *** *
** ** * * *** * ***** * * * * * * **** * *   * * *     ** * * break;
* ** * ***** ** * ** * * * ** * * * * ****** *** *   }
** ***** ** * * * * * * **** * * * * * * ****** *** *** * **
* * * ** **** *** * * * * ** ** * ** * ** ** {
** *** ** *** * ***** * * * ** *** *** *   *   *** * ** *
* ** * ** * * ** **** ** **** * *** * ** ** *   }
**** * * * * * * * * * * **** ***** * ** * ** * * * ** ******* ** *
* * * * * *** ** ** * * *** *** ****
* ** * * * ** * * ** * ** **** *** ** ** *** * *
**** ** * *** * ** * * * * * * * * *** * **
* ** *** * * ** **** * *** ** ** *** ** * ** * **** * * * * ** * * * * * );
* * ** *** ** *** * ** ** * * * * *********


**** **   }
*       return 0;
}
answered by (114 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
-----------Re-judge-----------
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
.
answered by (215 points)
0 0
prog.c:1:1: error: expected identifier or '(' before '.' token
 .
 ^
0 like 0 dislike
Hidden content!
* * ** * * ** *
** ** * * * *** *
int main()
{
** * * ** ***** char arr[100];
* * **   ** ** **** ****** *
*** * * ** {
* ** * * * *** * ** * ** * int * * * ******
** * * * * **** * ** *** ** * * * *
******* *** ** *** * ** ** {
** *** * * * * * *** *     **** * * ')
* **   **   ** * ** ** * * * * ** * ** count++;
** ** * ** * * * * ** **** * * * **
* ***** ** * * *** * * * *** * * * * break;
* *** * * * * ** * ** * }
* * *** * * * * * ** *** * ** ** * * **
** * * * *** }
** * ***** return 0;
}
answered by (100 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
** *** * ** ****
* ** ***** ****** *** **
int main()
{
***** ** ** *** char arr[100];
**** *   * * *** **** **
* * * * * {
* *** * * * * * ** int * * * **** * *
** * *** ** * ** * * * ** *
* ** ** *** **** ** ** {
** * *** *** * * ****     * ** ** ')
***** *   *   ***** * **** **** ** * count++;
** *** * ** * * * * * ** ** * **
* ** ** * ***** * * ** ** * ** ** break;
* *** ** * * * * ** }
* * * **** * * * ** * * * * ** * *** ***** * * *
** ** * * **** }
* ** ** * return 0;
}
answered by (100 points)
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()
{
* ** *** char arr[100];
*   **** * ** ***
** * * * * {
* ** * * *** * *** * * * int ***** * ** **
* * * ** * * * * *
** * *** ** **** * **** {
** * ** ** *** * *     ** ** ** ')
*** * **   * **   ** ** * * * * * * count++;
***** * * * * ** * ** *** * *** * * ** *****
* * ** ** * ** *** ** ** *** * ****** *** ** break;
*** *** *** * ** * }
* * * * ** * * * * * * * ** ******* * * *
* *** }
* * * ***** return 0;
}
answered by (100 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
* * * ******* * *
int main()
{
 int i,x=1;
 char a[1000];
* * **** *** *****
* * ** ***** *
 {

* **** ** ** *** * * *** * * ')
* ** ** * *** ** * * ***
* * ****** ** *** ** * * ** * * **** ***
* *** *** * * *****
****** * *** **** ** * * ** ** ** *
** ** ** * ** ** ** * * * * * * ***
 }
***** ** ** ** **** ** *
 return 0;
}
answered by (236 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
   int i,j=1;
** ** * * * *** str[1000];
* ** ** ** ** ** **** *** ***
* **** *** * ** * * ** * ** ***** *
   {
** * * ** ** * ** ** ** ** * ** ')
* * ** * **** ***** * * * ** * *** ** * ** ** ***
* * * **** * * **** * ** **
* *** ** * * ** **** ** * *
***** * ******* * *** ** ** *** **** ** * * ** ** * **
* * ***** * ** *** *** ** *
** ** * * *** **
* *** ** * ** * **** ** * * *** * * **

 return 0;
}
answered by (172 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: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>

int main(){
* * ** ** ** * * * * ** ** ***** **** *** *** ***** * ** ***
    int n=0,i=0;
*** *** * ** * * * *** * * * * *
    char s1[1000];
* **** ** * *** * * *** * ***
** * * ******* *** * * ** * ** * * *
** ** * * * * * ** * * **** ** to judge the string
    int flag=0;
* * * * * ** *** ** ** **** * * * ** **
    int k=strlen(s1);
* * * ** * *** * ** * * * *
* **** ***** * * ** **** ** * * ** ***
* * * ***** ** * ** *** *** ** ** ** ***** * ****** * ******* ** * * * * ** *** ** *** ** * * * *** ** *
* * **** ** * ******** ** ***** * * * * * * * * ** ** * ****** ****
* * *** * * * *** ** ** **** **** ** ** **
* ** * * ** * **** **** * * * ***
* ** ******** ** ** * *** *** * ** * ** *** ** * ** ** *** * *****
* *** * **** * *** * * * * **** *** ***** * ** *** * * * * * * * * * * **
** ** *** * * ** * ** * **** * * * ** **** ** * **** ** * ** ** * * * ** **** **** *
*** * ****** * * * * * ***** ** ** ***** *** ****** ***** *** ****** * *
** * * * * ** * * * * *** * *** ** ** *
    }
answered by (212 points)
edited by
0 0
prog.c: In function 'main':
prog.c:10:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(s1);
     ^~~~
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/ccr4cALP.o: In function `main':
prog.c:(.text+0x39): warning: the `gets' function is dangerous and should not be used.
0 0
prog.c: In function 'main':
prog.c:26:5: error: expected declaration or statement at end of input
     }
     ^
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>

int main(){
    
* ** ** *** * ** ** * * n=0,i=0;
    
** * * ** * * * *** * ** ** s1[1000];
    
* ** * *** **** * ** * ** *** ** ** * * *
    
* * ** * *** * * * * flag=0;
    
* ** ***** ** * * ** k=strlen(s1);
    
* * **** ** * **** * * *** * * * **
*** *** * *** * *** * * ** *** * * * ** ** * * * ****** ** * * * * ** * ** * * * ** * * * *** * *
** *** * ** **** ** * * * * ** * * * * *** ** * * * * *
** * ** * * ** ** ** * * ** * * ***** * **
** * ** ** * * *** ***** ** * * * * * ** ** *
* *** * **** * *** ** ** * ** * ** * ** * ** * *** * ** * * *** *
** * ** * * * * ** * * * * *** * * * * ** *** ********* * ****** * ** * *** * *** *** *
* *** ** ** * * ** * ** * * * * * * ** * **** ** ** * * * * * *** *** * *
* * ** * *** * * * * ** ******* **** ** ** *** ********* **
* * * *** * ** * ** * ** * ** **
* ** ** * * ** * *

** * * ** ** ** ** * *** ** * ** *** **
* *** * * * ** * **** 0;
}
answered by (194 points)
edited by
0 0
prog.c: In function 'main':
prog.c:7:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(s1);
     ^~~~
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/ccJQH56O.o: In function `main':
prog.c:(.text+0x39): warning: the `gets' function is dangerous and should not be used.
0 0
prog.c: In function 'main':
prog.c:7:11: warning: format not a string literal and no format arguments [-Wformat-security]
     scanf(s1);
           ^~
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
* ** ** ******* *
* * * ** * *** * ****
int main()
{
**** * ** * * *** char * **
* * ** ** int ** = 1;
** * * * * * ** ***
****** *** * for (j = 0 ; str[j] != * )
**** * * * {
*** * * * ** ***** * *** * ** *** == ' ')
**** * ** ************* ****
* **** * * **** * *** * **** *** * * **** * ** = count + 1;
* * *** ** *** ** * *
* ** * * * * }
* ** **** * ** ** ** **** **** *** **
** * * * * return 0;
}
answered by (209 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.127.216
©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
| 2.9k 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
| 3.2k 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
| 599 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.1k 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.1k views
12,783 questions
183,443 answers
172,219 comments
4,824 users