number of letters

 

The meaning of the question is to enter a string of strings. By deleting a single character, the string has only 2 or less different letters and the number of deletions

Idea: Store the occurrence of each character of the string separately and set the character type to -2.

 1 #include <stdio.h>  
 2 #include <math.h>  
 3 char a[105];
 4 int sum[105];
 5 int main()
 6 {int nchar[26]={};
 7     scanf("%s",a);int x=0;
 8     for(int i=0;a[i];i++)
 9     {
10         if(a[i]>='a'&&a[i]<='z') ++nchar[a[i]-'a'];
11     }
12     for(int i=0;i<26;i++)
13     
14     {
15         if(nchar[i]) x++;
16     }
17     if(x<=2) printf("0\n");else
18     printf("%d\n",x-2);
19 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324782957&siteId=291194637