统计文本单词的个数
2014-11-15 12:59
253 查看
《数据结构》实验四: 字符串和多维数组 实验
.实验目的
巩固字符串和多维数组相关知识,学会运用灵活应用。
1.回顾字符串和多维数组的逻辑结构和存储操作特点,字符和数组的物理存储结构和常见操作。
2.学习运用字符串和和数组的知识来解决实际问题。
3.进一步巩固程序调试方法。
4.进一步巩固模板程序设计。
.实验内容
1.从键盘输入一些文本,统计文本单词的个数
源代码:
#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
int dancishu(char str[])
{
int count = 0;
int state = 1;
int i = 0;
while (str[i] != '\0')
{
if (str[i] == ' ')
{
state = 1;
}
else if (state == 1)
{
state = 0;
count++;
}
i++;
}
return count;
}
int main()
{
char T[100];
cout << "请输入字符串:";
cin.get(T, 100);
cout << "输入的字符串为:" << T << endl;
int length = 0;
length = dancishu(T);
cout << "字符串中单词的个数为:" << length << endl;
system("pause");
return 0;
}
.实验目的
巩固字符串和多维数组相关知识,学会运用灵活应用。
1.回顾字符串和多维数组的逻辑结构和存储操作特点,字符和数组的物理存储结构和常见操作。
2.学习运用字符串和和数组的知识来解决实际问题。
3.进一步巩固程序调试方法。
4.进一步巩固模板程序设计。
.实验内容
1.从键盘输入一些文本,统计文本单词的个数
源代码:
#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
int dancishu(char str[])
{
int count = 0;
int state = 1;
int i = 0;
while (str[i] != '\0')
{
if (str[i] == ' ')
{
state = 1;
}
else if (state == 1)
{
state = 0;
count++;
}
i++;
}
return count;
}
int main()
{
char T[100];
cout << "请输入字符串:";
cin.get(T, 100);
cout << "输入的字符串为:" << T << endl;
int length = 0;
length = dancishu(T);
cout << "字符串中单词的个数为:" << length << endl;
system("pause");
return 0;
}
相关文章推荐
- 第四章实验:统计文本单词的个数
- 【ThinkingInC++】4、统计txt文本中单词的个数
- 统计文本中每个单词的个数
- C#统计文本单词的个数
- 实验四-1 统计文本单词的个数
- Python 统计文本中单词的个数
- 统计文本英文单词总个数,并列出每个单词的个数
- 第0004道练习题_Python统计文本里单词出现次数
- 利用PYTHON快速统计数字|单词在文本中出现的次数
- 判断是否为素数和统计字符串中单词的个数
- python---在文本/文章中统计字符串中出现单词次数
- 统计字符串中单词的个数
- Linux下统计文本文件中前n个出现频率最高的单词
- 第十六周项目二:用指针玩字符串(4) :统计句子str中单词的个数
- 统计文本文件中单词出现频率(用java集合框架编写)
- Java 文件统计:编写程序,统计英文文本文件中的字符数目和单词数目。程序运行时,输入要统计的文件的名称,程序处理后输出字符数目和单词数目
- python统计文本字符串里单词出现频率的方法
- python实现统计文本中单词出现的频率
- (hdu step 5.2.2)统计难题(求一堆单词中以某一单词为前缀的单词的个数)
- 对文本中不同单词出现的次数统计