frostblooded

New Task 3

Nov 18th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     char string[1000];
  5.     fgets(string, 1000, stdin);
  6.  
  7.     int ascii_letters[26];
  8.  
  9.     int i;
  10.     for(i = 0; i < 26; i++) {
  11.         ascii_letters[i] = 0;
  12.     }
  13.  
  14.     for(i = 0; string[i] != '\n'; i++) {
  15.         int ascii_letter = string[i];
  16.  
  17.         if((ascii_letter >= 'a' && ascii_letter <= 'z') || (ascii_letter >= 'A' && ascii_letter <= 'Z')) {
  18.             if(ascii_letter >= 'A' && ascii_letter <= 'Z') {
  19.                 ascii_letter += 32;
  20.             }
  21.  
  22.             int letter_num = ascii_letter - 'a';
  23.             ascii_letters[letter_num]++;
  24.         }
  25.     }
  26.  
  27.     for(i = 0; i < 26; i++) {
  28.         if(ascii_letters[i] > 0) {
  29.             char ascii_letter = i + 'a';
  30.             printf("%c - %d\n", ascii_letter, ascii_letters[i]);
  31.         }
  32.     }
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment