}*/
#include<stdio.h>
#include<string.h>
int n;
char str[100];
struct words
{
char word;
int number;
}wordstable[100];//wordstable[100] = {{ 'a',1 }, { 'd',2 }};
int tw(char str[100], char s);
int tw(char str[100], char s)
{
int i;
int count = 0;
for (i = 0; i < n; i++)
{
if (str[i] == s)
count+=1;
}
return count;
}
void tablew(char str[100])
{
int i,j;
for (i = 0; i < n; i++)
{
wordstable[i].word = str[i];
wordstable[i].number = tw(str, str[i]);
printf("%c,%d\n", wordstable[i].word, wordstable[i].number);
}
for (i = 0; i < n; i++)
for (j = i+1; j < n; j++)
if (wordstable[i].word == wordstable[j].word)
{
wordstable[j].word = wordstable[j + 1].word;
wordstable[j].number = wordstable[j + 1].number;
n--;
j--;
}
}
void main()
{
printf("input str:\n");
scanf_s("%s", str, 100);
void tablew(char str[100]);
int i,j;
n = strlen(str);
char str2[100];
tablew(str);
for (i = 0; i < n; i++)
{
printf("%c\t%d\n", wordstable[i].word, wordstable[i].number);
}
i = 0;
while (wordstable[i].word != '\0')
{
str2[i] = wordstable[i].word;
i++;
}
str2[n] = '\0';
puts(str2);
}
C语言实现字符串中删除字符中重复的字符
最新推荐文章于 2023-12-02 11:34:57 发布
本文介绍了一个使用C语言编写的程序,该程序能够统计字符串中每个字符出现的次数,并进行去重处理。通过构建一个结构体数组来记录每个字符及其对应的出现频率,最后输出处理后的字符序列。
3058

被折叠的 条评论
为什么被折叠?



