假设一个包含n(0<n<=15)个单词的词典:{"the","more","data","better","performance","of","machine","learning","algorithms","which","one","is","important","in","or"} ,输入n的值,基于此词典统计文本里单词出现的次数。
给定文本:the more the data, the better the performance of machine learning algorithms.
输入:15
则输出:4 1 1 1 1 1 1 1 1 0 0 0 0 0 0
输入:3
则输出:4 1 1
在这里给出一组输入。例如:
15
输出样例:
在这里给出相应的输出。注意输出格式,最后有一个空格。
4 1 1 1 1 1 1 1 1 0 0 0 0 0 0
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
/*取巧
#include <stdio.h>
int main()
{
int n,i;
int s[15]={4,1,1,1,1,1,1,1,1,0,0,0,0,0,0};
scanf("%d",&n);
for(i=0;i<n;i++)
printf("%d ",s[i]);
printf("\n");
return 0;
}
*/
#include <stdio.h>//干货
#include <string.h>
int main()
{
int n,i,j;
char s[15][20]={"the","more","data","better","performance","of","machine","learning","algorithms","which","one","is","important","in","or"};
char t[186]={"the more the data, the better the performance of machine learning algorithms."};
scanf("%d",&n);
for(i=0;i<n;i++)
{
char q[20]={'\0'};
char w[20]={'\0'};
int cnt=0,l=0;
strcpy(q,s[i]);
for(j=0;t[j]!='\0';j++)
{
if(t[j]>='a' && t[j]<='z')
{
w[l]=t[j];
l++;
}
if(t[j]==' ' || t[j]=='.')
{
if(strcmp(q,w)==0)
cnt++;
l=0;
for(int k=0;k<20 && w[k]!='\0';k++)
w[k]='\0';
}
}
printf("%d ",cnt);
}
printf("\n");
return 0;
}