You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

28 lines
540 B

  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. int count(char s[], char c) {
  5. int cnt = 0, sz = strlen(s);
  6. for (int i = 0; i < sz; ++i) {
  7. if (tolower(s[i]) == tolower(c))
  8. cnt++;
  9. }
  10. return cnt;
  11. }
  12. void countAll(char s[]) {
  13. int sz = strlen(s);
  14. for (int i = 0; i < sz; ++i) {
  15. int cnt = count(s, s[i]);
  16. if (cnt > 0)
  17. printf("%c:%d%s", tolower(s[i]), cnt, (i == sz - 1 ? "\n" : ", "));
  18. }
  19. }
  20. int main() {
  21. char s[257];
  22. scanf("%s", s);
  23. countAll(s);
  24. }