不知道错哪,大佬救我!!
查看原帖
不知道错哪,大佬救我!!
952584
laugh_001楼主2023/8/30 20:36

为什么输入beijing,对应的输出是No Answer 0,不应该是maxn=2,minn=1,差值为1吗;

#include<bits/stdc++.h>
using namespace std;

int main(){
	string s;
	ios::sync_with_stdio(false);
	getline(cin,s);
	unordered_map<char,int> mp;
	for(int i=0;i<s.length();i++){
		mp[s[i]]++;
	}
	int m=INT_MAX,M=1;
	for(auto x:mp){
		m=min(m,x.second);
		M=max(M,x.second);
	}
	int res=M-m,flag=1;
	for(int i=2;i<res;i++){
		if(res%i==0){
			flag=0;
			break;
		}
	}
	if(flag&&res>=2) cout<<"Lucky Word";
	else cout<<"No Answer";
	cout<<endl;
	cout<<res;
	
}
	

各位大佬救救

2023/8/30 20:36
加载中...