0 like 0 dislike
17.4k views

Please write a program, the user will enter a line of characters, then the program will calculate number of digits, alphabets and another characters.

寫一個程式 輸入一個字串,計算字串裡的數字、英文字母和其他符號的次數。

Example input:

1234567890Ancdefghijklmnopqrstuvwxyz~!@#$%^&*()_+

Example output:

digit:10
alphabet:26
other:13

 

[Exercise] Coding (C) - asked in Chapter 13: Strings by (5.2k points)
ID: 40715 - Available when: 2018-01-04 18:00 - Due to: Unlimited

edited by | 17.4k views

53 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>

int main()
{
*** * * * * **** * **** a[100];
***** *** ** ** * ********* *
* * * * ** ***** * len = strlen(a),i,j,k,l,x = 0,y = 0,z = 0;

* * * * * * * ** * = 0 ; i < len ; i++)
    {
* * *** * ** * * * ** ** *** *** ** = 0 ; j < 10 ; j++)
** ** **** * ** * * * * * ** * * * * ** ***** *
**** **** * ** * *** ** * * **** * * * ** **** * ***** ** *** *** == a[i])
* ***** *** * * *** **** ** ** * ** * ** ** * **** *** * * ** * *** * * * * *
* * * ** * * ** * **** ** *** * *******
*** * ** * ** **** **** * * ** * ** *** * **** * * = 0 ; k < 26 ; k++)
* ***** **** * ** ** * * * ** * * * *** *** *** *
* *** ***** * *** * ** * * ****** * *** * ** ** * ** **** ** * * == a[i] || 'a'+k == a[i])
** ** ** * * ** *** * * **** **** * ** ** ** ** ****** * ** ** ******* * * ** * *** **
* ** * ***** * * ** ** ** ******* * **** *
** *** * *** * *** * * * * ** * ** * ** *** = len-x-y;
    }

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

* *** * * * * ** ** **** 0;
}
answered by (-258 points)
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
*** **** * * *****
** **** *** *
int main(void)
{
*** ****   char s[1000];
* * * ** * *** ** * * ** * *
* * * ** ** int i;
* ** * **** * int * *
* * ** * * ** * * **** ** ***
* ** ** * {
* **** ** ** * * ** ** **** * * *** *** * ****
* * ** * * * * ** * ** * * * {
* *** * ****** ** ** *     d+=1;
****       }
* ** *       else * * * * * *** ** ** *** * * **** ** * **** ** **
* * * ***** *** * * {
****** * * *** ** ** *** ** ** a+=1;
***** *** * * * ** * ** *** }
* * ** ** * ** else
** **** * * * *** ** *** * {
* * * ** ** *** * ***** ** * oth+=1;
* * ** * * *** ***** * }
** ** * * *** }
** * **   * * * * * * ******* d);
**** * *** * * ** * ****** ** * ***** * a);
*** ***** * *** **** ** * * * * ***** oth);
* ***** ** * ** * *** * 0;
}
answered by (-249 points)
edited by
0 0
prog.c: In function 'main':
prog.c:12:15: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
  for(i = 0; i<strlen(sentence); ++i)
               ^~~~~~
prog.c:12:15: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:12:15: note: include '<string.h>' or provide a declaration of 'strlen'
0 0
Case 0: Correct output
Case 1: Correct output
0 0
prog.c: In function 'main':
prog.c:6:10: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[1000]' [-Wformat=]
  scanf("%s",&sen);
          ^
0 0
prog.c: In function 'main':
prog.c:7:10: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[1000]' [-Wformat=]
  scanf("%s",&sen);
          ^
0 0
Case 0: Correct output
Case 1: Correct output
0 0
prog.c: In function 'main':
prog.c:7:10: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[1000]' [-Wformat=]
  scanf("%s",&sen);
          ^
0 0
prog.c: In function 'main':
prog.c:7:10: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[1000]' [-Wformat=]
  scanf("%s",&sen);
          ^
0 0
Case 0: Correct output
Case 1: Correct output
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>

int main()
{
*** ** * * ****** * * a[100];
** ** * * * * * * * ** *** * * * *
* *** * * * * * *** * len = strlen(a),i,j,k,l,x = 0,y = 0,z = 0;

** * ** ** ***** * * *** = 0 ; i < len ; i++)
    {
** *** * * * ** * * * * * ******* * ** **** = 0 ; j < 10 ; j++)
* * * **** *** ** *** * * * * * ****** * ***
* * ** * **** * * * ** * *** * *** **** ** ***** * * * * ** == a[i])
** * ** * ** * * * ** ** * * ** ** * **** * * ** * ** * * ** * * ** * * * *
*** * * ** ** * *** * ***** * *** ** * **
*** ******* * **** * *** *** **** * * * *** * = 0 ; k < 26 ; k++)
***** * * ** * ***** * * **** * *
***** ** * * ** ** * *** * * * *** ** * ** * ** ** * * ** * * *** ** *** * == a[i] || 'a'+k == a[i])
** * ***** * ** ** * ** ** ***** * ****** ** * * ** * ** ** ** ***** ** * * * ** ** **
** * **** * * * * ** * **** * *** * ** ** ** *
** * ** * * ** *** ** ** **** *** ** * * = len-x-y;
    }

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

*** * * * *** * * *** ** 0;
}
answered by (-255 points)
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100

int main()
{
** * ** * * * *** str[MAX_SIZE];
** *** ** ** ** ** ** * alphabets, digits, others, i;

*** * * *** * ** *** * = digits = others = i = 0;
**** * *** * ** **** **** ** ****** **

*** ** *** ****** * * * *
* ** **** * * ***** * *
* * *** * ** ** ** ** ** * * * * **** * *** **** ** && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
* *** ** * *** * ** ** * ***** ******** ** ** *** *
* * **** ** * ** * ** ** *** **** ** * * **** * * * * *
** ** * * * **** * ****** * *** * * **
** * ** ** * ** * * * ** * ****** * * * * ** * * if(str[i]>='0' && str[i]<='9')
* * * * ** ***** ** * *** * **** * ******
* *** *** **** * *** * ** ** ******** * *** **** ****** * * * ** * *
** * *** **** * * * *** * *** ** *
* ** * ** **** * * ***** ** * *** * ** ** **** ***
* * * * **** * *** * ** ** * * ***
* **** ** ******* * *** * ** * * * * ** ** ** * *** * **
*** * * *** ** * * * ** * * **** **** * *

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

******** * **** * ***** * ***** ** * * * digits);
* * * * * * * ** *** ** * ***** alphabets);
* * * ***** * ** **** * * * others);

**** ** *** ** * **** * * 0;
}
answered by (-168 points)
0 0
prog.c: In function 'main':
prog.c:11:5: 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/ccUZH0tM.o: In function `main':
prog.c:(.text+0x38): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100

int main()
{
* ** * * ** *** *** str[MAX_SIZE];
** * * ** * * * * ** ** alphabets, digits, others, i;

* **** ** ** *** ** ** ** = digits = others = i = 0;
* ** ****** * * ** * * * ** * * * &str);
* ** * * ** * * * **

* ***** * ** * ****** ***** * ** *** **
* * **** * ** * *
* * *** **** ** * ** **** * * * ** * ** ** * *** *** && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
** ** **** * ** * **** * **** ** ***** * **
** * * ** * * * *** * **** *** *** * * ** * ** * * ******* * *****
* ** * *** * * ***** * *** * ** ***** * **
* **** **** **** ** **** * ** * **** * ** *** * * ** if(str[i]>='0' && str[i]<='9')
*** * ** ** *** ***** ** * * * ***** *
* *** *** **** ** * ** **** * *** * * **** * * ** ** * ** ** **
** ** * * * * *** * * *** * * *** ** * ** *****
* * * ** ** ** ** * *** * * * * * * ***
****** * * * * * * * ** * * ** * * *
* ** **** *** *** * * ** *** * * **** ** ** **** ** ** ** * ****
* *** * * *** ** * * ** * ******** ** * ***

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

* ** * * * * * * * ** * * ** ***** * ** digits);
** *** * * ** *** * * *** **** ** * * ** * * alphabets);
***** *** ****** * * ****** ** * **** * * ** others);

*** * * ** **** **** ** 0;
}
answered by (-168 points)
0 0
prog.c: In function 'main':
prog.c:11:11: warning: zero-length gnu_scanf format string [-Wformat-zero-length]
     scanf("", &str);
           ^~
prog.c:12:5: 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/ccNXoqk6.o: In function `main':
prog.c:(.text+0x50): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include <stdio.h>
#define MAX_SIZE 100

int main()
{
** * * * * * * **** * str[MAX_SIZE];
***** * * ***** ***** alphabets, digits, others, i;

*** ** * * * * ***** * = digits = others = i = 0;
*** ** ** * ** ** * ** ******* ** ** &str);
* *** *** ** * *** ** *** *

*** ** ** **** * * * ******** * *
****** ******** * * ** **
* *** ** * *** * ** ** ** * ***** * * * ***** ****** && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
* * *** * * * * ** * ** **** * ** * **** *
******* * * **** * * *** *** * ** * ** * * *** **** * ** * * ** *
*** **** * **** * * * * *** *** * **
** ** * ***** * ***** * * ** ***** * * if(str[i]>='0' && str[i]<='9')
* *** ** * * * *** ** *** * * ** * * ***
*** * ** * ** * ***** ** ****** * ** *** *** ** ** * ** * ** *** **** * **
*** **** ** * * ** ***** ** ***** **
* * **** * * * **** *** ** ** * ** * * *
** * * * * * ** * ***** * * * ***** *
* * *** * *** * * * ** *** *** * **** *** ** * ** * **** * * *** * *
*** ** *** ** * * * *** *** ** * ** * ** * ** *

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

* * *** ** ****** * *** *** * * ** * * * * digits);
* * ** ** *** * * *** ** ** ** ** *** *** alphabets);
* ** * *** ** * ** ** ** ***** *** ** * ** * * ** others);

* **** *** *** * * 0;
}
answered by (-168 points)
0 0
prog.c: In function 'main':
prog.c:10:11: warning: zero-length gnu_scanf format string [-Wformat-zero-length]
     scanf("", &str);
           ^~
prog.c:11:5: 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/ccinxSTa.o: In function `main':
prog.c:(.text+0x50): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include <stdio.h>
#define MAX_SIZE 100

int main()
{
* * * * ** * ** * str[MAX_SIZE];
******* * **** ** * ** * ** alphabets, digits, others, i;

* **** ** * * * ***** = digits = others = i = 0;

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

***** ** *** * * * * * *** **** *
    {
******* *** ** * * ** ** * *** ** * ** ** ** && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
**** * * * ** *** *** *** * * * * * * *
*** ** ** * * * ** **** *** * * * * *** **** *** ** ** **** *** **** ** *
*** ****** * * *** * * ** ** * * * * ** *
** ***** * * *** * * *** ** *** * if(str[i]>='0' && str[i]<='9')
* ** *** * * *** * ** * * **** ** **
* ** * * * **** * * *** * * * ** * ***** ** * *** **** * * **
*** *** * ** * *** * * ***** ** **
* * ****** * *** **** * **** ** * * *
**** * ** ***** **** * **** ** ** ** *
** *** ** * * ** * * * * * * * *** ***** *** * * * * ** ** *
* * **** * * ** * ***** ** * * * **

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

**** **** **** * * * ** * * * * * digits);
* * * * * *** * ** ** * * * * ** alphabets);
* ** *** *** *** * * **** * * *** * * others);

* *** * * * *** * * 0;
answered by (-168 points)
0 0
prog.c: In function 'main':
prog.c:11:5: 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:35:5: error: expected declaration or statement at end of input
     return 0;
     ^~~~~~
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
* * * * * ***** * * * * str[100];
** * * *** ***** * ** alphabets, digits, others, i;
* * ** * ** ** **
* * *** * ** * * * ** * = digits = others = i = 0;
** * ** ** * * *** *** ** * ("%[^\n]%*c", str);
  
* * * *** *** * * *** * *** *** *
* * *** **** * *** *** *
**** * ***** * ** * *** * *** **** *** * ** ** && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
** ** * * ** ** ******* * ** *** ***
*** * * * ** ** ** * * ** * * ** * * * **** ** * * * * * ****** *
* * * * *** * *** ** * ****** *
* ****** * * ** * *** ** ** *** ****** if(str[i]>='0' && str[i]<='9')
* * * * * * * * * ***** ****** * * ***** *** * * *
**** ** * ** * *** * * *** * * *** * ****** ** * **** * *** * *
** * ** ** * * ** * ** * *** ***** *
* ******** * *** *** *** ** * ** ** **** *
* ***** * ** * ****** * * ** * ** **
**** * *** * * * ** **** ** ** * * * ** ** * * ****** ****** ** ** ** ** **
* * *** * ** ** * * * ** * * * * *** *
** * * * * * ** * ** * **** ** * ** ** * **
**** ** ** * * **
*** * * *** * * * **** * * ** * * * * *** digits);
* * ** ** * * * ** * * * * * ** ** * alphabets);
* ********* ** ** * ***** * ***** others);
    
* ** * ** * * * * 0;
}
answered by (323 points)
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
* ******* ** ** * * ** ** string[100];
* ** ** * ** ***** * ** ** * s = string;
* ** * ***** * * * ** * a,d,o;
    
* *** ** * * * *** ****** * = d = o = 0;

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

**** * * ** *** ** * ** *
* ** * * * * ** **** *** ** *
* *** * *** *** * * * ** *** * ** ** **** >='a' && *s<='z') || (*s >='A' && *s<='Z'))
******** ******** ** *** * * *** * ** ****
**** ***** ** ** * * * * * * * ***** *** ** * **** * * ** * *
*** * ** ** * ****** **** ** *** * * * * **** *
* *** * * * * ** * *** *** * ** * * * ** if(*s>='0' && *s<='9')
* ** * ** * ** * ** ****** ** * * * *
* * **** * *** * * * * ****** * * ***** **** **** **** * ** ** ***** * *
** **** *** ** * ** * * * *** * * * *****
** * ** * * *** * * ** ****** * *****
* * ****** * ** * * *** * ** ***** * * * *** * **
* **** **** * ** *** * ****** * * ***** ***** * ** * **** * * **
* * ** * * *** * *** * ** ***** * ** **
* ** *** ** * **** ******* ** * ** *
* ***** ** * * * * ** * * **** *** **** **
** * ** ** * *****
   
    
*** *** *** ** * ** * *** ***** *** **** * * * **
   
**** ** * * * * *** * * 0;
}
answered by (-193 points)
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()
{
*** ** * * *** * * string[100];
* * ** *** * * ** ** *** * s = string;
** ** * * **** * a,d,o;
    
** ** ** * * * * = d = o = 0;

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

* * * * * *** * **
    {
*** * *** ***** ** *** ** ***** *** * **** * *** * ** >='a' && *s<='z') || (*s >='A' && *s<='Z'))
* * *** * ********** * * * * * * * **** **
* ****** *** *** ** ** * *** ** * ***** *** * * ** **** * * *
* ** ***** * * ** **** * *** ** ** * * *** *
* ** *** ** *** ****** ** ** * * * ** * if(*s>='0' && *s<='9')
** **** ** *** ** * *** * * * ** * ** **
* **** ** *** * * ** ** * * * * * * ** *** * ** * * * *
** * ** * * * * * ***** ** ** *** ** * * ** * **
** *** * *** * * * * *** ** ** * * * ***** *
* * * ** * ** ** ** * *** * ** ***
** * *** *** ** ** *** * * **** ***** * * *** ** * ** * * * ** * ** * **
*** * * *** * ** * * ********** **
*** * ** * * ** ** ** ** * * ** ***
**** * ** ******* * * * ** * **** * * ** * ***
* ** *** *** *** ***
* ** * ** ** * ** * **** *
    
** ** ** * * *** ** * ** ** * *** * * * **
   
** ** * * * *** ** 0;
}
answered by (-193 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:104.23.197.65
©2016-2026

Related questions

0 like 0 dislike
53 answers
[Exercise] Coding (C) - asked Jan 4, 2018 in Chapter 13: Strings by semicolon (5.2k points)
ID: 40713 - Available when: 2018-01-04 18:00 - Due to: Unlimited
| 14.5k views
0 like 0 dislike
27 answers
[Exercise] Coding (C) - asked Jan 11, 2018 in Chapter 13: Strings by thopd (12.1k points)
ID: 41439 - Available when: Unlimited - Due to: Unlimited
| 13.6k views
0 like 0 dislike
44 answers
[Exercise] Coding (C) - asked Jan 4, 2018 in Chapter 13: Strings by semicolon (5.2k points)
ID: 40714 - Available when: 2018-01-04 18:00 - Due to: Unlimited
| 12.5k views
12,783 questions
183,442 answers
172,219 comments
4,824 users