2020 Winter Holiday 【gmoj2403】 【Word word】 【String】

Title description

FJ wants to calculate the goodness of the names of his N (1 <= N <= 1000) cows. The name of each cow is a string of English letters no longer than 1000. He created a collection of good names, the number is M (1 <= M <= 100), the length of each good name does not exceed 30, and each of the cow ’s names contains a good name ("contains" does not necessarily require continuous) , Then its goodness is increased by 1. All names are not case sensitive. For example, the name "Bessie" contains "Be", "sI", "EE", "Es", but does not contain "eB".
Now please help FJ to calculate the goodness of each cow name.

Input

Line 1: Two integers N and M separated by spaces;
Line 2 ... N + 1: Line i + 1 is the name of the i-th cow;
Line N + 2 ... N + M + 1: Line N + i + 1 is the ith good name.

Output

Line 1 ... N: The i-th number is the goodness of the name of the i-th cow.

Sample input

5 3
Bessie
Jonathan
Montgomery
Alicia
Angola
se
nGo
Ont

Sample output

1
1
2
0
1

prompt

Input description: FJ has 5 cows with the names "Bessie", "Jonathan", "Montgomery", Alicia "and" Angola ", and 3 good names are" se "," nGo "and" Ont ".
Output description: "Bessie" contains "se", "Jonathan" contains "Ont", "Montgomery" contains "nGo", "Ont", "Alicia" does not contain any good names, "Angola" contains "nGo".

analysis

First of all, you can find that this question is case-insensitive, and pay attention when judging. Other direct violence enumerates every string, every good name. Because each good name contributes at most 1 to each string, you can just compare each character directly.
Note: When using char, you need to calculate the length and save it, and the card will not time out!

Code on

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m;
char a[1001][1001],g[101][1001],ff[1001];
int main()
{
    freopen("word.in","r",stdin);
    freopen("word.out","w",stdout);
    scanf("%d%d",&n,&m);
    getchar();
    for(register int i=1;i<=n;i++)
    {
    	scanf("%s",&a[i]);
	}
	for(register int i=1;i<=m;i++)
	{
		scanf("%s",&g[i]);
	}
	for(register int i=1;i<=n;i++)
	{
		int ans=0;
		for(register int j=1;j<=m;j++)
		{
			int s=0,len=strlen(a[i]),len1=strlen(g[j]);
			for(register int k=0;k<=len-1;k++)
			{
				if(a[i][k]==g[j][s]||abs(a[i][k]-g[j][s])==32)
				{
					s++;
				}
				if(s==len1) 
				{
					ans++;break;
				}
			}
		}
		cout<<ans<<endl;
	}
	fclose(stdin);
	fclose(stdout);
    return 0;
}

Published 110 original articles · 100 praises · 8024 visits

Guess you like

Origin blog.csdn.net/dglyr/article/details/104906069