Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- /* Tra ve index tim thay cua c trong mang arr[]
- Neu khong thay: tra ve -1 */
- int indexOf(char c, char arr[], int size) {
- int i;
- for (i = 0; i < size; i++) {
- if (arr[i] == c) {
- return i;
- }
- }
- return -1;
- }
- int main() {
- system("cls");
- //INPUT - @STUDENT:ADD YOUR CODE FOR INPUT HERE:
- char s[51];
- gets(s);
- // Fixed Do not edit anything here.
- printf("\nOUTPUT:\n");
- //@STUDENT: WRITE YOUR OUTPUT HERE:
- char characters[51];
- int count[51];
- int i, size = 0, index;
- for(i = 0; i < strlen(s); i++) {
- if (s[i] >= 97 && s[i] <= 122) { // a-z
- /* check xem co trong mang characters hay chua?
- neu co roi: tang count 1
- neu chua co: them vao mang characters */
- index = indexOf(s[i], characters, size);
- if (index != -1) { // tim thay ~> tang count 1
- count[index]++;
- } else {
- characters[size] = s[i];
- count[size] = 1;
- size++;
- }
- }
- }
- printf("%c_%d", characters[0], count[0]);
- for(i = 1; i < size; i++) {
- printf(" %c_%d", characters[i], count[i]);
- }
- //--FIXED PART - DO NOT EDIT ANY THINGS HERE
- printf("\n");
- system ("pause");
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement