AC了,但为什么?
查看原帖
AC了,但为什么?
858275
youshuohan楼主2024/9/21 19:23

这是我AC前的代码

#include <bits/stdc++.h>
using namespace std;
string st[100];
long long f[200],ans;
bool h[100][100];
bool com(string s1,string s2)
{
	int f1=s1.find(s2),f2=s2.find(s1);
	return (f1!=0)&&(f2!=0);
}
int main()
{
	int n;
	cin>>n;
	memset(f,0,sizeof f);
	for(int i=1;i<=n;i++) cin>>st[i];
	sort(st+1,st+1+n);
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) h[i][j]=com(st[i],st[j]);
	for(int i=1;i<=n;i++)
	{
		f[i]=1;
		for(int j=1;j<i;j++) f[i]+=f[j]*h[i][j];
		ans+=f[i];
	}
	cout<<ans+1;
	return 0;
}

但在输入后加了个对st[]的排序就AC了,为什么?

2024/9/21 19:23
加载中...