假设一个包含n(0<n<=15)个单词的词典,输入n的值,基于此词典统计文本里单词出现的次数。

假设一个包含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;
}

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浮央乜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值