日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

洛谷 P2908 [USACO08OPEN]文字的力量Word Power

發布時間:2025/3/14 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 洛谷 P2908 [USACO08OPEN]文字的力量Word Power 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

P2908 [USACO08OPEN]文字的力量Word Power

題目描述

Farmer John wants to evaluate the quality of the names of his N (1 <= N <= 1000) cows. Each name is a string with no more than 1000 characters, all of which are non-blank.

He has created a set of M (1 <= M <= 100) 'good' strings (no

longer than 30 characters and fully non-blank). If the sequence letters of a cow's name contains the letters of a 'good' string in the correct order as a subsequence (i.e., not necessarily all next to each other), the cow's name gets 1 quality point.

All strings is case-insensitive, i.e., capital letters and lower case letters are considered equivalent. For example, the name 'Bessie' contains the letters of 'Be', 'sI', 'EE', and 'Es' in the correct order, but not 'is' or 'eB'. Help Farmer John determine the number of quality points in each of his cow's names.

約翰想要計算他那N(l < =N <= 1000)只奶牛的名字的能量.每只奶牛的名字由不超過1000個字 符構成,沒有一個名字是空字體串.

約翰有一張“能量字符串表”,上面有M(1 < =M < =100)個代表能量的字符串.每個字符串 由不超過30個字體構成,同樣不存在空字符串.一個奶牛的名字蘊含多少個能量字符串,這個名 字就有多少能量.所謂“蘊含”,是指某個能量字符串的所有字符都在名字串中按順序出現(不 一定一個緊接著一個).

所有的大寫字母和小寫字母都是等價的.比如,在貝茜的名字“Bessie”里,蘊含有“Be” “si” “EE”以及“Es”等等字符串,但不蘊含“Ls”或“eB” .請幫約翰計算他的奶牛的名字 的能量.

輸入輸出格式

輸入格式:

?

  • Line 1: Two space-separated integers: N and M

  • Lines 2..N+1: Line i+1 contains a string that is the name of the ith cow

  • Lines N+2..N+M+1: Line N+i+1 contains the ith good string

?

輸出格式:

?

  • Lines 1..N+1: Line i+1 contains the number of quality points of the ith name

?

輸入輸出樣例

輸入樣例#1:?復制 5 3 Bessie Jonathan Montgomery Alicia Angola se nGo Ont 輸出樣例#1:?復制 1 1 2 0 1

說明

There are 5 cows, and their names are "Bessie", "Jonathan", "Montgomery", "Alicia", and "Angola". The 3 good strings are "se", "nGo", and "Ont".

"Bessie" contains "se", "Jonathan" contains "Ont", "Montgomery" contains both "nGo" and "Ont", Alicia contains none of the good strings, and "Angola" contains "nGo".

思路:暴力

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,m; int ans[1001]; char c[31],s[1001][1010]; bool judge(int pos,int j,int k){if(c[pos]>='A'&&c[pos]<='Z') c[pos]+=32;if(s[j][k]>='A'&&s[j][k]<='Z') s[j][k]+=32;if(c[pos]==s[j][k]) return true;else return false; } int main(){scanf("%d%d",&n,&m);for(int i=1;i<=n;i++)scanf("%s",s[i]);for(int i=1;i<=m;i++){scanf("%s",c);for(int j=1;j<=n;j++){int len=strlen(s[j]);int pos=0;for(int k=0;k<len;k++)if(judge(pos,j,k)) pos++;if(pos==strlen(c)) ans[j]++;}}for(int i=1;i<=n;i++)cout<<ans[i]<<endl; }

?

轉載于:https://www.cnblogs.com/cangT-Tlan/p/7846708.html

總結

以上是生活随笔為你收集整理的洛谷 P2908 [USACO08OPEN]文字的力量Word Power的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。