#include #include #include #include #include #include void swap(int &x, int &y){ int temp = x; x = y; y = temp; } void sort(int *a){ int i, j; for (i = 0; i < 126-32+1 - 2; i++){ for (j = 126-32+1 - 1; j > i; j--){ if (a[j] > a[j - 1]){ swap(a[j], a[j - 1]); } } } } void kyTuXuatHienNhieuNhat(char *s){ int temp; //tao bang ascii mau de so sanh int ascii[95]; for(int i = 0; i < 95; i++){ ascii[i] = 0; } //tim` so lan xuat hien cua cac ky tu for(int i = 0; i < strlen(s); i++){ for(int j = 0; j < 95; j++){ if(s[i] == j+32){ ascii[j]++; } } } //tao mang copy cua so lan xuat hien cua cac ky tu int asciiCopy[95]; for(int i = 0; i < 95; i++){ asciiCopy[i] = ascii[i]; } sort(ascii); //tim vi tri cua ky tu xuat hien nhieu nhat for(int i = 0; i < 95; i++){ if(asciiCopy[i] == ascii[0]){ temp = i + 32; } } printf("\nky tu %c xuat hien %d lan", temp, ascii[0]); } int main(){ char str0[100], str1[100]; printf("input String: "); gets(str0); kyTuXuatHienNhieuNhat(str0); return 0; }