存在感???(5分)給定函數(shù) frequency 的功能是:求字符串(子串)在字符串(一個段落)中出現(xiàn)的次數(shù)。函數(shù)接口定義:int?frequency?(?char*?paragraph,?char*?from,?char*?to?);其中 paragraph指向的空間中存放著一個字符串,from與to分別指向子串的第一個字符和最后一個字符。函數(shù)返回值為指定的子串在字符串中出現(xiàn)的次數(shù)。裁判測試程序樣例:#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;
}
/*?您提交的代碼將放置在這里?*/輸入格式:第一行為一個正整數(shù)N,0<N<=1000; 第二行為一個長度不超過N的可能包括空格的字符串; 第三行為兩個正整數(shù),分別為子串的第一個字符和最后一個字符的在第二行的字符串中的位置(不是下標(biāo))。輸出格式:一個正整數(shù)。輸入樣例: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
- 0 回答
- 0 關(guān)注
- 2489 瀏覽
添加回答
舉報
0/150
提交
取消