给定函数 frequency 的功能是:求字符串(子串)在字符串(一个段落)中出现的次数。
int frequency ( char* paragraph, char* from, char* to );
其中 paragraph指向的空间中存放着一个字符串,from与to分别指向子串的第一个字符和最后一个字符。函数返回值为指定的子串在字符串中出现的次数。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int frequency ( char* paragraph, char* from, char* to );
int main()
{
    int N;
    char *s;
    int from,to;
    int freq;
    scanf("%d\n",&N);
    s = (char *)malloc((N+1)*sizeof(char));
    gets(s);
    scanf("%d %d", &from, &to);
    freq = frequency ( s, s+from-1, s+to-1 );
    printf("%d\n",freq);
    return 0;
}
/* 您提交的代码将放置在这里 */第一行为一个正整数N,0<N<=1000; 第二行为一个长度不超过N的可能包括空格的字符串; 第三行为两个正整数,分别为子串的第一个字符和最后一个字符的在第二行的字符串中的位置(不是下标)。
一个正整数。
300 The Weather Channel and weather.com provide a national and local weather forecast for cities, as well as weather radar, report and hurricane coverage. 28 30
4
相关分类