#include "stdio.h" #define NUM 10 intmain() { char string[NUM]; int count[255]={0}; int i,j,k,num=1; gets(string); printf("Unprocessed pre-array: %s\n",string); //remove duplicate characters in the array for(i=0;string[i]!='\0';i++)//traverse and compare the data of the character array one by one { for(j=i+1;string[j]!='\0';)//Fix a character in a character array and compare the rest of the characters with it { if(string[i]==string[j])//If it is the same, then delete the redundant characters, which is actually to replace other characters and move them forward { for(k=j;string[k]!='\0';k++) { string[k]=string[k+1]; } count[string[i]]++;/*The ASCII code is mainly used here to connect the two arrays, string[i] corresponds to an ASCII code, and then the ASCII code is used as the array count entry to count the characters But only the number of characters with repeated occurrences can only be counted here*/ } else { j++; } } } printf("Processing late array: %s\n",string); for(i=0;i<256;i++) if(count[i]!=0) printf("The number of %c is %d\n",i,count[i]+1); }
Remove and count duplicate characters in a string
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325749721&siteId=291194637
Ranking