题解 P2264 【情书】
怎么又没有p的题解啊?那我来水一发

题目描述:求taoyc给hyw的情书中能让hyw感动的单词的数量(求放过)

显然,因为1 ≤ n,m,k ≤ 100,故可以直接暴力,只不过有点坑,要注意特判一下

代码:不吸氧貌似也能过

// luogu-judger-enable-o2
var
s:array[0..100005] of ansistring;
i,j,n,k,m,t,l,p,t1,ans,t2,t3,t4:longint;
s1,s2,s3:ansistring;
f:boolean;
begin
readln(n);
for i:=1 to n do begin readln(s[i]); s[i]:=lowercase(s[i]); end;//lowercase表示把s[i]统一转小写
readln(s1);
for i:=1 to length(s1) do
if s1[i]=',' then s1[i]:=' ';//因为,与' '有相同的作用,故把,转为' ',
s1:=lowercase(s1);//作用同上
l:=1;
while true do
begin
t:=pos('.',s1);//寻找'.'在s1中的位置
if t=0 then break;
s2:=copy(s1,l,t-l+1);//把这一段copy出来下面直接查找s2
delete(s1,l,t-l+1);//把'.'给删掉避免误判
p:=1;
while true do//这段是来感动hyw的单词的(求放过)
begin
t1:=pos(' ',s2);
if t1=0 then break;
s3:=copy(s2,p,t1-p);//s3是一个单词
f:=true;
for i:=1 to n do if s3=s[i] then begin inc(ans); f:=false; break; end;//查找这个单词是否在s中出现过
delete(s2,p,t1-p+1);
while true do//如果出现过,那么删去重复的单词
begin
if f then break;
t4:=pos(s3,s2);
if (t4=0) then break;
delete(s2,t4,length(s3));
end;
end;
s3:=copy(s2,p,length(s2)-p);//因为这种方***漏下最后一个单词,所以特殊处理一下
for i:=1 to n do if s3=s[i] then begin inc(ans); break; end;
delete(s2,p,t1-p+1);
end;
s3:=copy(s1,p,length(s1)-p);
for i:=1 to n do if s3=s[i] then begin inc(ans); break; end;
writeln(ans);
end.
ps:I love hyw ——taoyc (求放过)

C++党的放个我同学的代码QWQ:

include

include

include

include

include

using namespace std;
map<string,bool> t;
int n;
long long ans;
string a[105];
int main(){
cin >> n;
for (int i=1;i<=n;i++){
cin >> a[i];
for (int j=0;j<a[i].size();j++)
if ('A'<=a[i][j]&&a[i][j]<='Z') a[i][j]+=32;
}
getchar();
char s[1005];
gets(s);
for (int i=0;i<strlen(s);i++)
if ('A'<=s[i]&&s[i]<='Z') s[i]+=32;
for (int i=1;i<=n;i++){
string now="";
for (int j=0;j<strlen(s);j++)
if (s[j]==' '||s[j]==','||s[j]=='.'){
if (!t[a[i]]&&a[i]==now){
ans++;
t[now]=1;
}
if (s[j]=='.') t[a[i]]=0;
now="";
}else now+=s[j];
}
cout << ans << endl;
return 0;
}