编写函数void count(char a[],char w[][10],int n,int b[])。功能是:统计w指向的数组中的n个单词在a指向的字符串中各自出现的次数(将非字母字符看作单词分
2017-02-05 17:56
1566 查看
编写函数void count(char a[],char w[][10],int n,int b[])。功能是:统计w指向的数组中的n个单词在a指向的字符串中各自出现的次数(将非字母字符看作单词分割符),拧将统计结果依次保存在b指向的数组中。
#include <stdio.h>
#include <string.h>
void count(char a[],char w[][10],int n,int b[]);
int main()
{
char str[100] = "word/or.are,my&my.or/orhr;quit>time,word;my*";
char word[5][10] = {"word","my","quit","or","are"};
int b[5]; //b数组用来存放统计结果
int i;
printf("The strings array is :\n%s\n",str);
printf("The word array is :\n");
for( i = 0 ; i < 5 ; i++ )
{
printf("%-10s",word[i]);
}
count(str,word,5,b);
printf("\nThe w array words appear time in word :\n");
for(i = 0 ; i < 5 ; i++ )
{
printf("%-4d",b[i]);
}
printf("\n");
return 0;
}
void count(char a[],char w[][10],int n,int b[])
{
int i , j , k ;
int len , count ; //count用来记录单词个数,len用来记录有相同字符的个数
for( i = 0 ; i < n; i++ )
{
j = 0; //每一个单词都要从a数组的第一个字符开始做比较
count = 0; //每一个单词做一次计数记录
while( a[j] != '\0')
{
k = 0; //每做完一次比较w[i]都要单词的首字符
len = 0;
4000
if( isalpha(a[j]) ) //当a数组的元素是字母时,与w的单词作比较
{
while( w[i][k] == a[j] )
{
k++;
j++;
len++;
}
}
if( len == strlen(w[i]) && !isalpha(a[j]) ) //确保比较的是a数组分割符分割开的单词
{
count++;
}
j++;
}
b[i] = count;
}
return ;
}
程序运行结果:
The strings array is :
word/or.are,my&my.or/orhr;quit>time,word;my*
The word array is :
word my quit or are
The w array words appear time in word :
2 3 1 2 1
#include <stdio.h>
#include <string.h>
void count(char a[],char w[][10],int n,int b[]);
int main()
{
char str[100] = "word/or.are,my&my.or/orhr;quit>time,word;my*";
char word[5][10] = {"word","my","quit","or","are"};
int b[5]; //b数组用来存放统计结果
int i;
printf("The strings array is :\n%s\n",str);
printf("The word array is :\n");
for( i = 0 ; i < 5 ; i++ )
{
printf("%-10s",word[i]);
}
count(str,word,5,b);
printf("\nThe w array words appear time in word :\n");
for(i = 0 ; i < 5 ; i++ )
{
printf("%-4d",b[i]);
}
printf("\n");
return 0;
}
void count(char a[],char w[][10],int n,int b[])
{
int i , j , k ;
int len , count ; //count用来记录单词个数,len用来记录有相同字符的个数
for( i = 0 ; i < n; i++ )
{
j = 0; //每一个单词都要从a数组的第一个字符开始做比较
count = 0; //每一个单词做一次计数记录
while( a[j] != '\0')
{
k = 0; //每做完一次比较w[i]都要单词的首字符
len = 0;
4000
if( isalpha(a[j]) ) //当a数组的元素是字母时,与w的单词作比较
{
while( w[i][k] == a[j] )
{
k++;
j++;
len++;
}
}
if( len == strlen(w[i]) && !isalpha(a[j]) ) //确保比较的是a数组分割符分割开的单词
{
count++;
}
j++;
}
b[i] = count;
}
return ;
}
程序运行结果:
The strings array is :
word/or.are,my&my.or/orhr;quit>time,word;my*
The word array is :
word my quit or are
The w array words appear time in word :
2 3 1 2 1
相关文章推荐
- 编写函数void count(char a[],char w[][10],int n,int b[])。功能是:统计w指向的数组中的n个单词在a指向的字符串中各自出现的次数(将非字母字符看作单词分
- 编写函数 void count(char a[],char w[][10],int n,int b[]).功能是:统计w指向的数组中的n个单词在a指向的字符串中各自出现的次数(将非字符字符看作单词分割
- 编写函数void change(char *a,char *b,char*c)。 函数功能是首先把b指向的字符串逆向存放,然后将a指向的字符串和b指向的字符串按排列顺序交叉合并到c指向的数组中,两个字
- 编写函数void change(char *a,char *b,char*c)。 函数功能是首先把b指向的字符串逆向存放,然后将a指向的字符串和b指向的字符串按排列顺序交叉合并到c指向的数组中,两个字
- 编写函数void change(char *a,char *b,char*c)。 函数功能是首先把b指向的字符串逆向存放,然后将a指向的字符串和b指向的字符串按排列顺序交叉合并到c指向的数组中,两个字
- 编写函数void change(char *a,char *b,char*c)。 函数功能是首先把b指向的字符串逆向存放,然后将a指向的字符串和b指向的字符串按排列顺序交叉合并到c指向的数组中,两个字
- 编写函数void count(char a[],char w[][10],int n,int b[])。
- 编写函数void change(char *a,char *b,char*c)。 函数功能是首先把b指向的字符串逆向存放
- 小方法1——CountChar--统计一个字符串中每个字符出现的次数
- 编写函数void change(char *a,char *b,char*c)。 函数功能是首先把b指向的字符串逆向存放 然后将a指向的字符串和b指向的字符串按排列顺序交叉合并到c指向的数
- Sql统计一个字符串在另一个字符串出现的次数的函数-fnQueryCharCountFromString
- C语言编程练习5——编写函数void change(char *a,char *b,char*c)。 函数功能是首先把b指向的字符串逆向存放
- 请编写相关函数来完成对一段英文字符串进行字母统计功能,出现最多那个字母的出现次数,不区分大小写。
- 编写函数void change(char *a,char *b,char*c)。 函数功能是首先把b指向的字符串逆向存放
- C语言:编写一个程序统计输入字符串中,各个数字、空白字符、以及其他所有字符出现的次数。
- 利用字符重复出现的次数,编写一个方法,实现基本的字符串压缩功能。比如,字符串“aabcccccaaa”经压缩会变成“a2b1c5a3”。若压缩后的字符串没有变短,则返回原先的字符串。 给定一个stri
- 函数、数组区别以及函数注意点和回调函数,以及删除字符串中出现次数最少的字符的程序
- 编写一个程序统计输入字符串中: 各个数字、空白字符、以及其他所有字符出现的次数
- 编写一个函数,它从一个字符串中提取一个子字符串。函数原型如下: Int substr(char dst[], char src[],int start, int len) {} 目标是:从src数组
- 【php数组函数序列】之array_count_values() - 统计数组中所有值出现的次数函数