Saturday, August 18, 2018

MINIMUM FREQUENCY

  • Problem Description

    How to find lowest frequency character in a string using loop in C programming.
  • CODING ARENA
  • #include <stdio.h>
    #include<string.h>
    int main()
    {
      char str[100];
      int freq[225];
      int i=0,min;
      int ascii;
      scanf("%s",str);
      for(i=0;i<225;i++)
      {
        freq[i]=0;
      }
      i=0;
      while(str[i]!='\0')
      {
        ascii=(int)str[i];
        freq[ascii]+=1;
        i++;
      }
      min=0;
      for(i=0;i<225;i++)
      {
        if(freq[i]!=0)
        {
          if(freq[min]==0||freq[i]<freq[min])
            min=i;
        }
      }
      printf("%c=%d",min,freq[min]);
      

    return 0;
    }
  • Test Case 1

    Input (stdin)
    madam
    
    
    Expected Output
    d=1
  • Test Case 2

    Input (stdin)
    eefffggghhh
    
    
    Expected Output
    e=2

No comments:

Post a Comment