RUNTIME ERROR!!
查看原帖
RUNTIME ERROR!!
337016
Zhang_Z楼主2021/7/23 11:35
#include<bits/stdc++.h>
using namespace std;
struct node {
	string s;
	int count;
} Node[100];
int cmp(const void *a , const void *b ) {
	struct node *c = (node *)a;
	struct node *d = (node *)b;
	if(c->count != d->count) return c->count - d->count;
	else return d->s > c->s;
}
int juge(int a){
	int count=0;
	for(int i=1;i<=a;i++){
		if(a%i==0)
			count++;
	}
	if(count==2)
		return 1;  //是质数
	else
		return 0; 
}
int main() {
	string s1;
	int length;
	getline(cin,s1);
	length=s1.length();
	int max=0,min=0,count=0;
	map<string,int> mapS1;  //abaac
	string c;
	for(int i=0; i<length; i++) {
		c=s1[i];
		if(c!=" ")
			mapS1[c]++;
	}
	map<string,int>::iterator iter;
	int i=0;
	for(iter=mapS1.begin(); iter!=mapS1.end(); iter++) {
		Node[i].s=iter->first,Node[i].count=iter->second;
		i++;
	}
	qsort(Node,i,sizeof(Node[0]),cmp);
	max=Node[i-1].count;
	min=Node[0].count;
	int answer=max-min;
	if(juge(answer)){
		cout<<"Lucky Word"<<endl;
		cout<<answer;
	}
		
	else{
		cout<<"No Answer"<<endl;
		cout<<"0";
	}
		
	
}
2021/7/23 11:35
加载中...