满江红25pts,求助
查看原帖
满江红25pts,求助
1268524
DX3906_ourstar楼主2024/11/21 13:45

rt,代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
namespace OIfast{//快读快写 
	#define re register
	using namespace std;inline int read(){re int n=0,f=1;re char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')n=n*10+c-'0',c=getchar();return n*f;}inline void print(re int n){if(n<0)n=-n,putchar('-');if(n>=10)print(n/10);putchar(n%10+'0');}inline void write(re int n,re char c){print(n),putchar(c);}
};
using namespace OIfast;

const int N=1e2;
const int M=1e6+5;

int bucket1[N],bucket2[N],bucket[N];//三个桶 
int a,b,ans;
char s[M],t[M];

signed main(){
	char c=getchar();//输入 
	while(c!='\n')s[++a]=c,c=getchar();
	while(c<'a'||c>'z')c=getchar();
	while(c!='\n')t[++b]=c,c=getchar();
	for(re int i=1;i<=a;i++)bucket1[s[i]-'a']++;//统计 
	for(re int i=1;i<=b;i++)bucket2[t[i]-'a']++;
	for(re int i=1;i<=N;i++)bucket[i]=min(bucket1[i],bucket2[i]);
	for(re int i=1;i<=N;i++)ans+=bucket[i];//计算答案 
	write(ans,'\n');//输出 
	return 0;
}

注意到把所有数组都开到1e6会变成0pts,这是何故

2024/11/21 13:45
加载中...