A data compression software utilizes various steps to compress a string of data. One of the steps involves finding the count of characters that are not repeated on the string
#include <stdio.h>
#include <string.h>
int main()
{
char str[250];
char rep[250];
int i, j, len, check, cnt_not_rep, i_rep, temp;
printf("Enter string: ");
scanf("%[^\n]", str);
cnt_not_rep = 0;
i_rep = 0;
len = strlen(str);
for (i = 0; i < len-1; i++)
{
check = 0;
for (j = i+1; j < len; j++)
{
if(str[i] == str[j])
{
check = 1;
i_rep++;
rep[(i_rep - 1)] = str[i];
}
}
if (check == 0)
{
temp = 0;
for (j = 0; j < i_rep; j++)
if (rep[j] == str[i])
temp = 1;
if (temp == 0)
cnt_not_rep++;
}
}
check = 0;
for (j = 0; j < i_rep; j++)
if (rep[j] == str[len-1])
check = 1;
if (check == 0)
cnt_not_rep++;
printf("\nCount of characters that are not repeated: %d\n", cnt_not_rep);
}
Comments
Leave a comment