0 like 0 dislike
7.1k views
Write a program to count the highest occurrence of a single character in a string, Hint: This problem is only concerned with lowercase letters and single words, no sentences

example

input: aaaaaaaaaabb
output : 10

input: aaaabbbccccceeeezzzzzzz
output : 7
[Exam] asked in Midterm
ID: 23784 - Available when: Unlimited - Due to: Unlimited

reshown by | 7.1k views

47 Answers

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

#define MAX_SIZE 100 //Maximum size of the string

#define MAX_CHARS 255 //Maximum characters allowed





int main()

{
* *** ** * * * * * ** * string[MAX_SIZE];
**** ***** * ** * ** * ** ** frequency[MAX_CHARS]; //Stores frequency of each character
* ** * * *** **** * * i = 0, max;
***** ** * * ** * * * ** * ascii;
* ******** * * * * *
***** * ** * * ** ** * ** **
* * *** * *** *** ***
* * * * *** *** **** * * ** Initializes frequency of all characters to 0 */
** ** **** **** * * * * **** *** i<MAX_CHARS; i++)
** * *** ** * * * * *
* * * *** * * ** ** * ****** *** * * * * ** ****** = 0;
**** * **** *** **
** *** * * * * * * **
* * *** * *** ****
* *** ** * * * ** *** ** Finds frequency of each characters */
* * * * ** * *
***** ** * ** *** * * *** * * != '\0')
* * * *** * * * ***
** * * * * ** * **** * * **** * ** * **** = (int)string[i];
*** *** * * ***** * *** ***** ** *** += 1;
** ** ** ** * *** * * *** ** * *** ** *
* * ***** ** *** * ** ** ** * * * ****** * * * **
*** * ****** ** * *
***** ** * *** * **** **
* * * ** **** * * **
* * *** * **** * * Finds maximum frequency */
* * * *** * **** **** = 0;
* * ***** ** * *** * i<MAX_CHARS; i++)
* * * * * ****** ** * **
**** * * * * **** ** ***** ** *** ****** **** * * * > frequency[max])
** * ** * * * * ** * ** * * * * ******* * *** * ***** * ** ***** * = i;
* *** * * ** * ** **
* ****** * *
** ** **** *** ** *** *
** * ** ***** * *** ** *** * * ** * ** * ***
* ** * * **** * * * * *
* * ** **** **** * * ** ** ** 0;

}
answered by (38 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <string.h>



int main()

{
* ****** * * * * * * * i, count1 = 0, count2 = 0;
* *** ** **** ******* input[100];
** ** * **** * ** *** ** ****** *** * &input);
* * *** ** ** * ***** ** (i = 0; i < strlen(input); i++)
* ** * * * ** ** *
** * * ** ** ** ** * * ** ** * * *** * ** (input[i] == 'a')
**** **** * ** * ** * ** ** ** * ** * * *** ** ** * ** * * ** ** * ** ***
* ** * * ** ** * * *** * * * * * * *** * ** *
**** ** ******** *** ** *** ***** * * ** *** * ** ** *** * * ****** **
* **** * * ** *
* * * **** * * * * ** * (i = strlen(input) - 1; i >= 0; i--)
* * * * ** * * * * *
* ** * ** * ***** * ** * * *** * ** * * *** * == 'a')
** * * ** ****** * *** ** *** * * ** * * * ****** * ** ** *** **** * ** ** **
** * * ** * * * * *** * ******* **
* **** ** ** ** ** ** *** ** **** * * *** ***** ** * ******* *
* ** ******* *** * * * **
* * **** *** * ** * ** * (i = count1; i < strlen(input) - count2; i++)
* * * * * *** * * ** ** * ** * * * * * * * * * *** input[i]);
*** ** *** * ** 0;

}
answered by (38 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>



int main(){

    char input[100]={0};

    printf("input: ");
****** **** * * * * **** * * ** * * *** ** *
** **** ***** ** ****** * ** ********* *** * i;
* ***** ** ********** * ***** ******* * ** * max;
** ******* * * * *** **** *** * * temp;

        int sum[26]={0};
* ** * * **** * *** ** * ** ** * ** ** ** ***** * * * * * **
*** ** * * * * * * * *** ** *** *** * ** * *** * * ** * ** * * **** * * ** *** ** = input[i]-97;
* * *** ** *** ***** * * ****** ** **** *** ** * * * ** ** ** * * * * * *
* * * **** * * * ** **** * **** ** ** * ***** ** * *** **
* * * * *** * * * **** **** ***** ***** * * *** ** * *** ** * ** ***** ****** * *** *
* * * * * * * **** ** ** * ****** ** * ** ** * *** ** * *** ** * ** *** *** *** ** **** * * * *
* * * ******** ** * *** * * * **** ** * * * **** *** * * * * **** * *** *** ** * ** ** ** ** *** * * = sum[i];
*** **** * **** * * * * * ** * * ***** * ** * * ****** ** * * ** **
** * ** * * * * ** ****** * * ** * * ** * * ** * ****** **
* * ** * * *** * ** * * * ** *** *** ** ** *** * * ***** * * * **** * *** %d\n",max);
* * * * ** ** ** ***** ** **** * *** *** ** **** * ** *** ** **** input[100]={0};
* *** *** ** *** * ***** * * * * * * * * **** ** * * * * ** *** ** ** ");

        }
* ** * ** *** ** ** * *** ** ****** ** *** 0;

    }
answered by (24 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>



int main(){

    char input[100]={0};
* * * **** ** **** **** * * ** * * * * **
* * * * ** ** * * ** ** ** * *** ** * i;
* ** ** ***** * **** ** * * ** **** * **** * * ** max;
* * * * * ***** * ** * *** * * * ****** temp;

        int sum[26]={0};
*** *** * *** ** * ** * **** *** * * *** ******* * * ** *
*** * ** *** ** * ** ** *** ** * ** ** ** * * ** ** * * ********** *** * * ** * *** * ** = input[i]-97;
* * * ****** * ** **** * * * * *** * *** * * * * *** * ** * *** * *** * * ** ** ***
* * * ******** ** ** ** * * ** * * * ** *** * *** *** **** ** ** * *
* * * * ** ** ** * ***** *** * ** ** ** ** * * * * * ** ** **
* * ******* * * * ** **** * ** ***** ** * *** * ** **** * ** ***** ** ** *** **** * ** ******* ** *
*** ** ** * ** * **** **** * * ** ** * * ** ** * ** * **** **** ** **** * * * ** ** * ** * = sum[i];
* * **** **** * * ***** * * ******* * **** * ** ** * * * ***** ** * * ** *** *** * **** ****** *****
* * ** ** ** * ** **** * ** * ** * ********* * * ** * *
* **** ** ****** * * * ** * * * * * * * ** * *** **** * *** * ** *
* * * **** ** *** ******* **** * ** *** * * * * * ** *** * * **** * * *

        }
* * * * ** * *** ***** * * *** *** * 0;

    }
answered by (24 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>



int main(){

    char input[100]={0};
* * *** * **** * ******* ** * * * ** * ** *
*** * ** ** * ** * *** *** ****** * ***** * * i;
* * * * * * * * *** * ***** * ***** * * ** * *** max;
* * ** * ** * *** * ** ** * * * ** * temp;

        int sum[26]={0};
** * *** **** * *** * *** *** * * * * **** ** * * *
** * * * *** ** * ** * *** ** * * ** * * ** * * * *** ** * * ** *** ** * * ** = input[i]-97;
*** * ***** ** ** * **** *** *** ***** *** **** * * * * * * *** ** *** *** * * ** ***
* * * ** ** * ** ****** **** * * * ***** ** **** * ** ** **
* * * * ** * * ** * * * ***** * * ** * * * * * ** * ** ** *** * *** ***
* * ** * * * * * **** * * * **** ** * *** ** ** *** *** ** ** *** * * ***** **** **** * **
******** ** ** *** *** * * ** ** ** *** * * *** * * ** ***** * * **** ********** * * ** **** *** *** * ** = sum[i];
**** * * * * * ***** **** ** ** * * * ** ** ** * ** *** * ****** * * * ** * * *
*** **** * * ** * *** * **** * * * * ** ** * * * * ***
* * * * * * *** ** ***** * **** * * *** *** ** ** * *** ** *** ** ** *** *

        }
*** **** * ***** *** ** * * * ***** * ** * 0;

    }
answered by (24 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>



int main(){

    

    while(1){
***** ** ** ** * ** **** * ** ******** i;
** ** * ** * * *** * * * * * ** ******** ** max;
* * *** * *** * ** * * **** ** * * * * * * * temp;
*** ** ** * * * * **** ***** *** ** * ***** input[100]={0};

        int sum[26]={0};
* * * * * * ** **** ** * * ** * ******* ** ** * * ** * * ***
* * **** ** * * * * ** * **** *** **** * ***
** * * * * *** * * * **** * *** ****** ** * *** ** ** ** * * *** **** ** **** = input[i]-97;
* * * *** * * * ** ** * ***** *** *** ** * * * * * ** **** **** ** * * * ** *****
* **** * ** ** ** *** ****** * * * * ******** * ** * ** ****
* *** ***** **** ** ** * ** * * * ** * * * * **** ******** *** * ** *
* * ** ** * ** ** * * ** ** ** **** * * ** ** * * * * * ***** ** ***** **** * ** * ** *
** ** ** * ** ** * * * ** ** ** ** ** **** ****** ** * ******* *** * **** * * * * ** ** ** ***** ** * **** **** * ** = sum[i];
* * * *** * * ** ** * * * ** ** * ** * * ** *** ** * *** * ***** ***** * * *** **** ****
** ** ** * * **** *** *** * *** * * ** * * ** * *** **** ** *
** * * * * ** * ** ** ** * **** *** *** ** * ** * ********* * **** * * ** * ** ** * *
* * * * * ********* ** * * * ** **** * ** *** ** ** * * * **** * * ** 1;

        }
***** * * * * * *** * * *** * *** * * * 0;

    }
answered by (24 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>



int main(){

    

    while(1){

        int i;
* * * * * * ********* * ** ** ** ** * * max;
** * ** * *** **** * * ** ******** * ** ** * temp;
** ** ** ** * * * **** * ***** input[100]={0};
* * *** **** ** *** *** * * ** *** * * ** * sum[26]={0};
* * * * * * ** * * ** ** * * * ** ** * * * * **** * *** * *** ** **** **
* * * * ** * * ************* * * * ***** * * *** *** * **
** ** * *** *** * * * * * * ** * * ** ** * * *** ** * ** * *** ** * **** * ** = input[i]-97;
******* * * * **** * * * ** *** *** * * ** *** * *** * ***** * * * ** *** ***** **** * * * ***** * *
* * ** * **** * * * * ** * ** * ********* * *** *
** * * ** * *** ** ** ** * ** * * * ** ***** ** ** * * * **** * * **** ** **** *
* * ** ** ** * * * * * * ** ** * **** ** * * *** *** * ** * *** * * * ** *** ** * * ** *
** * *** * ** **** *** * * * * * * * *** ******* ** ****** *** ** ***** *** ** ****** = sum[i];
* * *** *** ** * * * *** * * ** * ***** * * * * * * * ***** **** ***** * * * * * *
** ** **** ** ****** * ** ** ***** * ** ** * * ** ** ** * ** ****** * *
* * * ****** * *** ** ** * * ** * * * ******* ** * * ** ** *** ** *** * ** *

        }
* ** * ******* ** *** *** ** * ** * * * 0;

    }
answered by (24 points)
0 like 0 dislike
Hidden content!
* ** *** * ** * **
*** * **** ** *

int * * *

char **

int ** *

int ** [25];

int i;

int j;

int len;

int temp;


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



for * * * * ***** * ** ****** * an * array
**** *** * **** *** * ****



for **** ** **** *** ** * ** * * * * an array * * * how many times each * * is ***
* * *** ** * * ** ** *



for *** * * ** * * **** *** ****** **** how many times that *** * is ** * and * that value in **
** *** **** * * * * *** ** **** *


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



}

}

for **** *** *** ** *** * * * * ** * * *** ** **** ***** * ** ** * * * ****** * * * ***** the **** array
* * * * ** ********** *** * * *

if (rep *** ** ** * **
** * * *** ** ** ** = rep [j];
*** ******** * ** ******* *** * * *
** ** * * ***** * * *
** *** **** *******

}
* ** * * * *** * * *** the array is ** the most * * **** be in *






** * 0;}
answered by (-34 points)
0 like 0 dislike
Hidden content!
#include *** * *** *

#include ****** * ***

#include ** * **** *****



int main()

{
* ** * * * * ** *** ** n[1000];
**** ** ** ** * * num[26]={0}, i, max = 0;


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


* * * ** * * * **** ** i<strlen(n); i++)
* *** ***** ** ********* * ** * * ** * * ***** * ** ** *


* **** * * ** *** * * * ** i<26; i++)
* * * ** ****** **
*** **** ** *** * **** ** *** * *** * * *** * **** < num[i])
** **** * ** * *** **** * * ** * ** * * ** *** * ** ** ** *** * = num[i];
**** *** **** *** *****


* **** * **** * * * * **** ** * ** max);


** * * * * *** **** * 0;

}
answered by (20 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#define max_len 100

#define max_char 255



int main()



{
* *** * * ** *** ** ** word[max_len];
**** ** * * ** * * ** *** freq[max_char];
** ** ** ** * * * ** ascii, i, max;


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


* * * * **** * * * i<max_char; i++)
* ** * * * * * ** *
****** * ** * *** * * * * *** * * ** *** * * * = 0;

    }
* ** * ** * * *********** ****
* * ** **** ***** *** * *** * * != '\0')
** **** * ** ** * * **
** * * ** * **** * * **** * * * * * *** = (int)word[i];
** *** *** *** * ** ** **** * * * ***** **** *** += 1;
* *** ** * * ** * * * * * *** **** ** * ** *** **
*** * **** **** *
* *** *** *** ** ** * * = 0;
* *** * ** * * ** * * i<max_char; i++)
** * * * **** * ***** *
* ****** * * ******* * ** * * * ** ** * * * > freq[max])
* * * * ** ** ** **** ** * * *** ** ***** ** * ** * *** * ** = i;
***** * **** * ** * **
* **** *** * * ** *** ** * ******* ** * ** * * *
*** * * * * ** * * ** 0;

}
answered by (-298 points)
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
13 answers
[Exercise] Coding (C) - asked Apr 21, 2017 in Midterm
ID: 24268 - Available when: Unlimited - Due to: Unlimited
| 2.6k views
0 like 0 dislike
11 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24270 - Available when: Unlimited - Due to: Unlimited
| 2.6k views
0 like 0 dislike
65 answers
[Exam] asked Apr 13, 2017 in Midterm
ID: 23786 - Available when: Unlimited - Due to: Unlimited
| 9.7k views
0 like 0 dislike
8 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24273 - Available when: Unlimited - Due to: Unlimited
| 1.8k views
0 like 0 dislike
4 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24272 - Available when: Unlimited - Due to: Unlimited
| 1.4k views
12,783 questions
183,442 answers
172,219 comments
4,824 users