0 like 0 dislike
13.2k views

Write a program that ask the user to input a serial character (max 1000). Prints a table showing how many time each digit appears in the number. You should see 'A' and 'a' as the same.

寫一個程式 求使用者輸入一字串(最大1000) 輸入字母出現的次數 (A跟a算一樣)

Example input

Write a program that ask the user to input a serial character. Prints a table showing how many time each digit appears in the number. You should see 'A' and 'a' as the same.

Example output

A 19
B 2
C 3
D 3
E 15
F 0
G 3
H 9
I 9
J 0
K 1
L 3
M 5
N 7
O 6
P 5
Q 0
R 10
S 10
T 13
U 5
V 0
W 3
X 0
Y 2
Z 0

 

[Exercise] Coding (C) - asked in Chapter 8: Arrays by (5.2k points)
ID: 39985 - Available when: Unlimited - Due to: Unlimited

edited by | 13.2k views

31 Answers

0 like 0 dislike
Hidden content!
#include ** * * * ** *
#include * *** * *
#define Max 1000

void * * * ** [], int []);
void * ** **** [], int []);

int main()
{
* * ** * ** * *** * * ***
* * * ** * * * ** c, count[26] = {0};

* ** * **** ** * Max, stdin );

* * * ** *** * ******** *** *** count);
* *** **** ** **** * * * * count);


* * * ** **** * * (c = 0 ; c < 26 ; c++)


*** * ** * * ** *** **** * ** *
* *** ** ** * * ** *** ***** * * * ** * * * * ****
** * ** ** * * **** * * * ** * *
************ * ** * * * ** * * * * * ** * ** ****** * * ** **** ** * * * * * *** c + 'A', count[c]);
* **** * **** *** * * *** * *
* * * ** * * ** **** * * **
**** ***** * * ** * * *** * * *** ** * * * * * * ** * *** **** * * * ** c + 'A', ** *


* * * ** ** * 0;
}
void *** *** * s[], int count[]) {
** ** * *** ***** * * * c = 0;

* *** *** * ** * (s[c] != '\0') {

** *** ** * **** * ** * *** * (s[c] >= 'A' *** * * *** s[c] <= 'Z'  )


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

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

void ***** s[], int count[])
{

* ** * ** * **** * * * **** c = 0;

* * *** * *** ** * (s[c] != '\0') {

** * * * * ***** ** * ** ** * (s[c] *** * * ** ** ** * * )


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

* * * *** * ****** * ** ** ****** * * **
****** * * ***
}
answered by (-140 points)
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include<string.h>
int main()
{
* * * ***** * ** * * * ** i,c,r,s, tab[100];
* ** *** * * *** * * * a,chaine[1001];
* ** * * ****** * ** *** *** * *
***** *** * * *** *** * *** * *
*** *** * *** * * * * **** * *
* ******* * * ** * ** *
* ** ** *** * * ** ** * * (a='a';a<='z';a++)
* * *** **** * *
*** * * ** * *** * ** * * *** ***** **** * * * *** ** * * * * ***
* ** ** * ** * * ** ***
*** * * ** * ** * **** ** * * * * * **** * ** ** ** * * ((chaine[i]==a) || (chaine[i]==a-32))
** ** ** * * ** * ** ** * ** *** **** *
* * *** *
* * *** * **** **** * * *
** * ***** ***** **** * * *
* * **** *** * * * * * (c=0;c<=25; c++)
** ** * ** * * *** * * *****
** ****** **** ** ** * ** * * *** * ** (c<25)
* **** ********* ** * * ** *** *** * **** ** * ** *** * %d\n",(c+65),tab[c]);}
* *** *** **** *** * *** * * * * ** **
*** *** ***** * ***** * * * * * * * *** * * *** ** * %d",(c+65),tab[c]);}
* ** * * * *** ****
* **** * * ** * ** ** * 0;
}
answered by (-168 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
prog.c: In function 'main':
prog.c:7:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(chaine);
     ^~~~
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/ccLui6ys.o: In function `main':
prog.c:(.text+0x26): warning: the `gets' function is dangerous and should not be used.
0 0
prog.c: In function 'main':
prog.c:7:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(chaine);
     ^~~~
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/ccZnZnXG.o: In function `main':
prog.c:(.text+0x26): warning: the `gets' function is dangerous and should not be used.
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
int main()
{
**** **** ** ** ** ** * ***** ** ** ** ** *** ****** ** ***** * * * * * * ** * * *
* * * ** ** * **** * * * ** *** * * ** * * ** ** * ** * ** * *** ** *
    int c[50]={0};
* ** *** *** ***** * **** d[1000];
    int n,i,j,l,z=0;
*** * * ** *** ** * * ****
** * * * * * ** **** * * *
** * *** * ***** * (i=0;i<n;i++)
    {
* ** ** * ** * ** ** * *** ** **** * (j=0;j<26;j++)
*** *** * * * * * *** *** *** ** ** * *
* * **** **** ** * * ** **** *** ** ** ** *** ***** ** (d[i]==a[j]||d[i]==b[j])
** ** * * * ** ** ****** * **** ** *********** ** * ** * ******
* * **** * *** *** **** * ** ***** ** ****** * * ******** *** ** ** **** * *** ** **** *** *
** *** * * * *** * ****** ** * ******** *** *** *** * * * * * * *
* * ***** * * * ** * * * * ***** * * *
    }
* *** * ** * *** * (l=0;l<26;l++)
    {
** *** * * ** * * * ** * ** **** ****** (z==0)
** ** *** ** * * ** *** **** *** *** * *
***** ** * * ** **** ***** * *** * * * * *** *** * ******* ** ** *** * %d",b[l],c[l]);
***** ** * * * * *** ** * * ** ** ** * ** *** * * ** ** ****
**** * * * * * *** ******* ** * **** ** ** ** *
** * ** * * *** * *** ** * *** ** * * * *
** **** ** * * ** *** * * * * ** **** ***
* **** * ** ** * * * *** ******* **** *** ** **** * * * **** *** * * ** *** %d",b[l],c[l]);
* *** * * * * * * * ** ******* * * * **** *
    }
** * * * * *** *** ** * 0;
}
answered by (-229 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
-----------Re-judge-----------
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include * * **** *
#include **** ***
#include * *** * ****
#include ***** * *** *
void * * * * * ***** src,char* dsc)
{
***** * * ** for(int i = **** ** * *
***** ** * dsc[i] = * * ** *
}
int main()
{
** ** * char * ****
* * * * * ** char t[1000];
***** ** * gets(t);
*** * ** ** * * *
***** **  

*** ** *** for(char * * * *
** **** * * {
** ** * * * ** * * * ** *** int count=0;
* * ** * * *** * * **** for(int ** * * * ** *
** * *** *** ** * * * * {
** * * * * * * * *** * * * ** **
** * * ** * *** ** ** * * * * ** ** * **
** * ** *** * ** * ** * ** * {
* *** *** ** * *** *** * **** ** * ** *** count++;
*** * ** ** * *** * ** ** ** * ***** }
* * * *   * * }
*** * * **** ** ** * * * * *** *
* * ** * ** * ** * ** * ** *** *** **
* * * ** * ** * * ** * **** **** ***** * * ** * * * ** * * * * ****** * ** ** * * ** * ******
* * *** ** * ** ***** ****** *** ****
*** ** * ** }
* *** ***
** * ** getch();
}
answered by (-214 points)
0 0
prog.c:3:19: fatal error: conio.h: No such file or directory
 #include <conio.h>
                   ^
compilation terminated.
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>

int A[26];//大寫
int a[26];//小寫

int main()
{
* ** * ** *** *** ** ** i;
*** * ** ** ** ** n[10000];
* ** ***** ** ** *** * * ***** ** ** *
**** * **** * *** ** *** *
* * ** ** ** * * * *** * * * * * ** ******* *
* ** * * * *** * * * * *******
* ** ** * *** ** * ** ** * ** ** * * * * * * * && n[i]<='z')
* ** ** *** *** *** * ** *** ** * * ** * * * * * ** * **** * * * ** *****
***** * ** *** **** * *** * * ** * **** * * * * ** * if(n[i]>='A' && n[i]<='Z')
** * * * * **** ** *** * * ** **** ** ** * * ***** * * *** ** * * ** **** *** *
** *** * ** *** *
* *** ** ***** * * **** *** *
* *** * *** ** * ** ** **** **** **** ** ** ** || a[i]!=0)
* *** ***** * * * * * * ** * *** *** * * * *** %d\n",i+'A',A[i]+a[i]);

** ** **** ** * ***** *** ** 0;
}
answered by (-32 points)
edited by
0 0
prog.c: In function 'main':
prog.c:16:38: warning: multi-character character constant [-Wmultichar]
          else if (n[i]>='A' && n[i]<='Zq')
                                      ^~~~
0 0
prog.c: In function 'main':
prog.c:12:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(n);
     ^~~~
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/ccfK7LFr.o: In function `main':
prog.c:(.text+0x25): warning: the `gets' function is dangerous and should not be used.
0 0
prog.c: In function 'main':
prog.c:12:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(n);
     ^~~~
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/cc7Hbocl.o: In function `main':
prog.c:(.text+0x25): warning: the `gets' function is dangerous and should not be used.
0 0
prog.c: In function 'main':
prog.c:11:15: warning: format '%[^
   ' expects argument of type 'char *', but argument 2 has type 'char (*)[10000]' [-Wformat=]
     scanf("%[^\n]",&n);
               ^
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
0 like 0 dislike
Hidden content!
#include *** ** *** **
#include ** * *** ** *
#define Max 1000

void **** ** * ** [], int []);
void ** ** * [], int []);

int main()
{
**** * * * ** **** ** * * *** **
* ** ** ** c, count[26] = {0};

** ** * * ** * ** ** Max, stdin );

* * * * ** * * * *** ** * * * count);
* ** ** * ** *** ** *** * count);


** ** ***** * * ** *** * (c = 0 ; c < 26 ; c++)


** **** *** **** ** ****** * * **
* * ** * * ** * * * ********** ***** ******* ** * * *** ** *
* * ** ** ** ** * ***** **
** * * **** * * *** * * ** ** ** * ** * ** * *** * ** ******** * ** * * * ** * * c + 'A', count[c]);
* * * ***** * ** ** **** *** * **
** *** *** * * ** **** *
* ** **** * * * * * ******* ** * *** * * **** * **** * ** ******* c + 'A', ** *


****** ** * * * * * ** 0;
}
void ** ***** * ** s[], int count[]) {
* ** **** * * * ** c = 0;

** * * ** (s[c] != '\0') {

*** * ** * ** * * ******* *** (s[c] >= 'A' * ** ** **** s[c] <= 'Z'  )


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

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

void ****** * s[], int count[])
{

* ***** ***** *** c = 0;

* **** * * * * ** (s[c] != '\0') {

* ** ***** * * ** ** *** * * *** (s[c] ** * * ** ** )


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

** ** *** * ** ******** * * * * ****
*** * ** ** ***
}
answered by (-167 points)
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
** * * * * ** *** * * string[1000];
* * ***** *** * * * c = 0, count[26] = {0}, x;
* * ** * * *** ** * * * ***
* ****** * ** * ***** ** ** ** *
******** * ***** * * * *
* *** * * *** * ** ** * (string[c] != '\0') {
**** **** ***** ** *** ** * *** * * *** * * *
* * ** ** * * ** * ** * * * * * * * * ** (tolower(string[c]) >= 'a' && tolower(string[c]) <= 'z') {
** **** ** * ** * * ** * ** * ** * ** **** * * ** ** ***** **** *** * ** = tolower(string[c]) - 'a';
* ** *** ** * * ** * * * *** ** ***** * ** ** ** * ** ** ** * ** **
* * * * ** * * * * * * ** * **** ***
* *** ** * * * *** * ** ** ** ** * * ** **
** ** ** ** * * ** ** **** ** * *** *
* ** * ** * * ** * * *
* **** ***** *** * *
* * ** * *** * ****** (c = 0; c < 26; c++){
* * * *** * * ** * * * * * * * * * **** ****
* * * * * * ** *** * ** ** ****** ** ** * * * * ** ** * %d",c+'A',count[c]);
*** * ** * *** ** *** * * ** ** ** * ***
* *** * * *** *** ** ** * ** * * * (c != 25)
*** * * * * * * ***** * ** * ** * **
***** * *** * ** * * * ****** * ** * ** ** ** * * ** ***** * * ***** *** * * ****
* ** **** * * * * *** ** **** ** * ** * * * ***** *
* ** * * * * ******
    
**** * * * * ** * 0;
}
answered by (323 points)
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include * ** * *** **
#include * ** *** ***

int main()
{
**** ** *** ***** ** ** string[1000];
** * *** * * **** c = 0, count[26] = {0}, x;
* * * * *****
* * * * *** ** ** ** * *** ** ***** **
* * *** * *
* * ** * *** *** *** * (string[c] != '\0') {
* ** * ** **** **** * **** * **** *
**** ** ** ** * ** * **** ** * ** *** * * ** ** (tolower(string[c]) >= 'a' && tolower(string[c]) <= 'z') {
* * ** **** * *** * * * * * * * ** * * * * **** = tolower(string[c]) - 'a';
* * * *** **** * * ** **** ***** * ** * **** *** * * * * * * ***
** ** * ******* * ** * * * * *** * ***** * **
*** * * * * * * ** ****** ****** *
** * ** * * * * ****** ** ** * ** * * *
* * * * * * * ***
* * * * * *
*** * * ** * * * ** * * (c = 0; c < 26; c++)
*** *** ** ****** **** ***** ** * * ** * ** ** %d ** * * * ** * **
** *** ****** * * * *
* *** * * *** ** * 0;
}
answered by (-193 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 like 0 dislike
Hidden content!
** * * * * *
* **** * * * *

int *
{
* * * * **** char *

*** *** * * *** * = *

** * * * ** * ** **
***** * *
* ** ** int len = * ** *
** * *
** * ** ** int j = 0;

* * ** ** * i = 0; i * i++)
* * * ** {
* * *** *** ** * * = 0; j *** * 26; j++)
* *** * **** * **** * * {
*** * ****** ** * * ** * ** * ** *** * * == 'A' + j || * == 'a' + j)
** * * * * * * ***** ** * {
** * * ** * **** * * ** * * * *** * ** * *
* * *** * * * ** * ** }
** * * * * * ** * * ** * }
* ** * * }
* * * **** **** = 0; j * 26; j++)
* * * **** * * ** * *** * == 25)
* * * ** ** ** *** * * * ** * * * * ** ** 'A' + j, **
* * ***** * ** * ****** **
**** ** * * * **** * * ** ** *** ***** * * *** ** *** * * 'A' + j, * *
}
answered by (-285 points)
0 0
prog.c: In function 'main':
prog.c:11:12: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
  int len = strlen(a);
            ^~~~~~
prog.c:11:12: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:11:12: note: include '<string.h>' or provide a declaration of 'strlen'
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>
char string[1000];
int ii,jj;
int ** * ** * * * ** *** * ** * * * ** *** * ** ***** *
int main()
{
    fgets(string,1000, stdin);
* * ** *** * * ** * * **
* * ** ** ** * * * **** ***** **** * ** ** * ** * * * * ** ***** * * **
** ** ** * * **** ***** * ** ** * ** ****** ** * * * ** ** *
* * ** ****** * * * ****** * ** **** * * ******* ** ***** * ** * * *
* * * *** *** * *** ** **** *** * * ** * ** ** *** ** **** ***
* * ** *** *** ** * * * ** ** ***** ** *** * ****** *** ** ***
* * **** ***** ** ** * ** *** * ** * ***** * * * * *** ******* ** * *
*** * * **** * * * *** * * * ** * * * * ** * * *** * ****
* ** * **** ***** *** *** ***** ** ********* * ** * *** * *******
* *** * ***** *********** ***** * *** *** * ** ** * ***** ** * **** *
** * *** * ****** * *** ** ******* ** *** ** * ****** * * * * * ** *
* * * ****** ** * ****** **** *** *** * * * * * * * * ** * *
* * **** **** * *** * ***** * ** ***** ******* * ** * * * ** * * **** * *
** * * *** * * **** ** ** ** ** ** * * ** **** * **
*** * ** * *** * * * * *** ** * * *** * * * ** **
** * ** * ***** *** *** * ** * ***** * * * * ** *** ** * ** * ** *
***** *** * * * ** * * * *** * ** * ******* * * ****
* ** ** * * *** * ** ** * * ** * * * ** * *** * * ***
*** * * **** * * ******* ****** * * * * * * * * * * * **
*** * *** * **** * * **** * * * * * ** * ** *** ***** *** ******* *
** * ** ***** **** * * ** * * ** * **** * ** ** ** *** ** ** ** *
* * ** **** * * * * ** * * * ******** ** * ** **** * * * *
*** **** * ******** * * ** ** * *** *** ** *** *** * * * ** ** *
*** *** * ** *** * ** ** ** * * * * * * ** ** *** * **
** * **** * * * * ** * ** ** ** * * * * ** * ** * * ** * * ** * * *
* * *** * ** * ** * ** ** ** * ** ** * *** ** *** **** * * ****
* *** **** ** * ** * * *** ** * * * * * * *** *** ** * * * * * ** *

    }
    printf("A %d\n",a);
    printf("B %d\n",b);
** ** * ** * ** * * *** * * * %d\n",c);
* **** ** *** ** * * ** ** * %d\n",d);
** **** * * ** * ** * * **** ** * %d\n",e);
* * *** * ** * *** * * * * * %d\n",f);
*** * * * * ** *** * * %d\n",g);
**** * * * *** *** ** ** * **** %d\n",h);
* * *** * *** ** ***** * *** %d\n",i);
**** * ****** ******* * * %d\n",j);
** ** ** * * * * * *** * *** %d\n",k);
* * * ** * ** ** * * * ** * * %d\n",l);
* ***** * * * ** *** * * ** * ** %d\n",m);
* * **** *** * *** * * ** * %d\n",n);
*** ** * ** * * * * ** ** ** %d\n",o);
* * * *** *** * * * ****** * * * %d\n",p);
** * * * * ***** * * * * * * %d\n",q);
* **** * ******* * **** *** * %d\n",r);
*** ** ** ** ** * ** * *** * * * * %d\n",s);
** *** ***** *** * * ***** * %d\n",t);
* * *** * * * * ** **** *** * ** %d\n",u);
* ***** ** * *** ** *** **** * ** %d\n",v);
    printf("W %d\n",w);
    printf("X %d\n",x);
    printf("Y %d\n",y);
** * ** * ** ** ** * *** ** ** * ** %d",z);

    return 0;
}
answered by (-284 points)
0 0
Case 0: Correct output
Case 1: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:104.23.243.108
©2016-2026

Related questions

0 like 0 dislike
102 answers
[Exercise] Coding (C) - asked Dec 28, 2017 in Chapter 8: Arrays by semicolon (5.2k points)
ID: 39984 - Available when: Unlimited - Due to: Unlimited
| 26.9k views
0 like 0 dislike
56 answers
[Exercise] Coding (C) - asked Nov 29, 2017 in Chapter 8: Arrays by semicolon (5.2k points)
ID: 34913 - Available when: 2017-11-30 18:00 - Due to: Unlimited
| 15.5k views
12,783 questions
183,442 answers
172,219 comments
4,824 users