1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-12-16 15:44:39 +00:00
202401-programming-assignments/【实践课内】14.指针2/6-3 存在感.md

55 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 6-3 存在感
给定函数 frequency 的功能是:求字符串(子串)在字符串(一个段落)中出现的次数。
### 函数接口定义:
```c
int frequency ( char* paragraph, char* from, char* to );
```
其中 paragraph指向的空间中存放着一个字符串from与to分别指向子串的第一个字符和最后一个字符。函数返回值为指定的子串在字符串中出现的次数。
### 裁判测试程序样例:
```c
#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;
}
/* 您提交的代码将放置在这里 */
```
###输入格式:
第一行为一个正整数N0<N<=1000;
第二行为一个长度不超过N的可能包括空格的字符串
第三行为两个正整数分别为子串的第一个字符和最后一个字符的在第二行的字符串中的位置不是下标)。
### 输出格式:
一个正整数
### 输入样例:
```in
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
```
### 输出样例:
```out
4
```