UVA409strstr()函数

这题可以用strstr()函数做也可以不用,贴上不用的,用strstr时注意单词不能被包含在一个更长的单词里面,

包含文件: string.h
函数名: strstr
函数原型:extern char *strstr(char *str1, const char *str2);
语法:* strstr(str1,str2)
str1: 被查找目标 string expression to search.
str2: 要查找对象 The string expression to find.
返回值:若str2是str1的子串,则先确定str2在str1的第一次出现的位置,并返回此位置到str1末尾的所有字符;如果str2不是str1的子串,则返回NULL。(注:若想返回str2在str1第一次出现的位置,不是这个函数)


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
char key[25][25];
char excuse[25][75];

int main()
{
    int k,e;
    int cas=0;
    while(cin>>k>>e)
    {
        getchar();
        cas++;
        for(int i=0;i<k;i++)
            gets(key[i]);
        for(int i=0;i<e;i++)
            gets(excuse[i]);
        int a[25];
        memset(a,0,sizeof(a));
        int amax=0;
        for(int i=0;i<e;i++)
        {
            char c[100],len=0;
            for(int j=0;j<strlen(excuse[i]);j++)
            {
                if(isalpha(excuse[i][j]))
                {
                    c[len++]=excuse[i][j];
                    c[len-1]=tolower(c[len-1]);
                }
                else
                {
                    c[len]='\0';
                    for(int x=0;x<k;x++)
                        if(strcmp(c,key[x])==0)
                        a[i]++;
                    len=0;
                }
                /*if(isalpha(excuse[i][j]))
                {
                    char c[100];
                    int len=0;
                    for(;j<strlen(excuse[i]);j++)
                    {
                        if(isalpha(excuse[i][j]))
                        {
                            c[len++]=excuse[i][j];
                            c[len-1]=tolower(c[len-1]);
                        }
                        else
                            break;
                    }
                    c[len]='\0';
                    for(int x=0;x<k;x++)
                        if(strcmp(c,key[x])==0)
                        a[i]++;
                }*/
            }
            amax=max(amax,a[i]);
        }
        printf("Excuse Set #%d\n",cas);
        for(int i=0;i<e;i++)
            if(a[i]==amax&&amax!=0)
            printf("%s\n",excuse[i]);
         cout<<endl;
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值