统计串S中字符的种类和个数方法2
来源:互联网 发布:pop端口号110访问不了 编辑:程序博客网 时间:2024/06/05 19:27
/*统计串S中字符的种类和个数*/
#include<cstring>
#include<iostream>
using namespace std;
#include<cstring>
#include<iostream>
using namespace std;
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
#define MAXSTRLEN 255 //用户可在255以内定义最长串长
//typedef char SString[MAXSTRLEN+1]; //0号单元存放串的长度
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
#define MAXSTRLEN 255 //用户可在255以内定义最长串长
//typedef char SString[MAXSTRLEN+1]; //0号单元存放串的长度
typedef struct{
char ch[MAXSTRLEN+1]; //若是非空串,则按串长分配存储区,否则ch为NULL
int length; //串长度
}SString;
Status StrAssign(SString &T, char *chars) { //生成一个其值等于chars的串T
int i;
if (strlen(chars) > MAXSTRLEN)
return ERROR;
else {
T.length = strlen(chars);
for (i = 1; i <= T.length; i++)
T.ch[i] = *(chars + i - 1);
return OK;
}
}
typedef struct {
char ch[MAXSTRLEN+1]; //若是非空串,则按串长分配存储区,否则ch为NULL
int length; //串长度
}SString;
Status StrAssign(SString &T, char *chars) { //生成一个其值等于chars的串T
int i;
if (strlen(chars) > MAXSTRLEN)
return ERROR;
else {
T.length = strlen(chars);
for (i = 1; i <= T.length; i++)
T.ch[i] = *(chars + i - 1);
return OK;
}
}
typedef struct {
char ch;
int num;
} mytype;
void StrAnalyze(SString S)//统计串S中字符的种类和个数
{char c;
mytype T[20]; //用结构数组T存储统计结果
int i,j;
for (i=0;i<=20;i++) T[i].ch='\0';
for(i=1;i<=S.length;i++)
{
c=S.ch[i];j=0;
while(T[j].ch&&T[j].ch!=c) j++; //查找当前字符c是否已记录过
if(T[j].ch)
T[j].num++;
else
{T[j].ch=c;T[j].num=1;}
}//for
for(j=0;T[j].ch;j++)
cout<<T[j].ch<<":"<<T[j].num<<endl;
}//StrAnalyze
int num;
} mytype;
void StrAnalyze(SString S)//统计串S中字符的种类和个数
{char c;
mytype T[20]; //用结构数组T存储统计结果
int i,j;
for (i=0;i<=20;i++) T[i].ch='\0';
for(i=1;i<=S.length;i++)
{
c=S.ch[i];j=0;
while(T[j].ch&&T[j].ch!=c) j++; //查找当前字符c是否已记录过
if(T[j].ch)
T[j].num++;
else
{T[j].ch=c;T[j].num=1;}
}//for
for(j=0;T[j].ch;j++)
cout<<T[j].ch<<":"<<T[j].num<<endl;
}//StrAnalyze
void main()
{SString S;
char*T="sasdddas1111as";
StrAssign(S,T);
StrAnalyze(S);
//count();
}
{SString S;
char*T="sasdddas1111as";
StrAssign(S,T);
StrAnalyze(S);
//count();
}
阅读全文
0 0
- 统计串S中字符的种类和个数方法2
- 统计串S中字符的种类和个数方法1
- C# 统计文章中字符的种类和个数 哈希表和字典的使用
- 统计字符串中字符的种类
- 统计字符串中字符种类的数目
- 统计字符中特殊字符的个数
- 统计字符串中字符的种类和每种字符出现的频率
- 统计字符串中各个字符的个数
- 统计字符串中相同字符的个数
- 统计字符串中字符的个数
- 统计字符串中各个字符的个数
- 统计字符串中某个字符的个数
- 统计字符串中各个字符的个数
- 统计字符串中各种字符的个数
- 统计字符串中每个字符的个数
- 统计字符串中不同类型字符的个数
- 统计字符串中字符出现的个数
- 统计字符串中字符的个数
- NLP大神推荐的机器学习入门书单(附大量百度网盘电子书)
- 数据库实验——2
- 小记
- 入坑集锦(二)
- 论文:HEIF
- 统计串S中字符的种类和个数方法2
- DRF-ModelViewSet 根据条件选择序列化
- 4.实验题
- 【1701H1】【穆晨】【171124】连续第四十五天总结
- [BZOJ2002][Hnoi2010]Bounce 弹飞绵羊(LCT)
- springboot源码分析2-springboot 之banner定制以及原理
- [网易]2018校园招聘编程题真题集合
- 我们为什么要用fitsSystemWindows?
- 设计模式—简单工厂模式