fork download
  1.  
  2. #include <iostream>
  3. #include <string.h>
  4. using namespace std;
  5. #define MAX 300
  6.  
  7. void DemKyTu(char s[]);
  8. int myStrcmp(char s1[MAX], char s2[MAX]);
  9. int myStrlen(char s[], int k);
  10.  
  11. int main()
  12. {
  13. char s[MAX];
  14. //gets(s); //Nhap chuoi s
  15. cin.getline(s, MAX);
  16. if(myStrcmp(s, "") == 0)
  17. cout << "Chuoi rong." << endl;
  18. else
  19. DemKyTu(s);
  20. return 0;
  21. }
  22.  
  23. int myStrcmp(char s1[MAX], char s2[MAX])
  24. {
  25. if(s1[0] == s2[0])
  26. return 0;
  27. return 1;
  28. }
  29.  
  30. void DemKyTu(char s[])
  31. {
  32. int arr[500], cnt[500];
  33. for(int i = 0; i < 500; i++)
  34. arr[i] = 0, cnt[i] = 0;
  35. int i = 0;
  36. while(s[i] != '\0')
  37. arr[int(s[i++])]++;
  38. i = 0;
  39. while(s[i] != '\0')
  40. {
  41. if(cnt[s[i]] > 0)
  42. {
  43. i++;
  44. continue;
  45. }
  46. cnt[s[i]]++;
  47. cout << s[i] << ": " << arr[int(s[i++])] << '\n';
  48. }
  49. }
  50.  
  51.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Chuoi rong.