184 条题解
-
-1205610760 LV 8 @ 2016-11-08 00:14:42
由于太懒。。于是priority_queue。。(反正不会TLE23333333)
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>using namespace std;
#define main int main(int argc,char *argv[])
#define PI 2*asin(1)char s[200];
int a[300];int c(int a){
for(int i=2;i*i<=a;i++){
if(a%i==0)return 0;
}
return a>1;
}priority_queue<int>m,n;
main{
scanf("%s",s);
for(int i=0;s[i];i++)a[s[i]]++;
for(int i=0;i<300;i++)if(a[i]!=0)m.push(a[i]),n.push(-a[i]);
int t=m.top()+n.top();
if(c(t))printf("Lucky Word\n%d\n",t);
else printf("No Answer\n0\n");
} -
-12016-11-05 09:30:29@
#include<algorithm> #include<cstdio> #include<cstring> #define f(x,y) for(register int x = 1; x <= y; x ++) using namespace std; int a[27]; bool shai[101]; int main() { char c[101]; shai[0] = 1; shai[1] = 1; for(int i = 2 ; i <= 100 ; i ++) if ( ! shai[i] ) for(int j = i * 2 ; j <= 100 ; j += i) shai[j] = 1; scanf("%s",c + 1); int len = strlen(c + 1); f(i,len) a[c[i] - 'a' + 1] ++ ; int maxn = 0, mini = 1e9 + 7; f(i,26) if (a[i]) maxn = max(maxn , a[i]),mini = min(mini ,a[i]); if(shai[maxn - mini]) printf("No Answer\n0"); else printf("Lucky Word\n%d",maxn - mini); return 0; }
-
-12016-11-04 20:37:41@
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>#define Coding using namespace std
#define For for(i=0;i<=Length+1;i++)
#define Ha for(i=1;i<=149;i++)
#define Explode return
#define AddOneSecond if
#define ReduceOneSecond else
#define Read scanf
#define Write printfchar String[105];
int i,Length,Numbers[150],Maxn=0,Minn=100;
bool PriNum(int);
Coding;int main()
{
scanf("%s",String);
Length=strlen(String);
For
{
AddOneSecond (String[i])
{
Numbers[int(String[i])]++;
}
}
Ha
{
AddOneSecond(Numbers[i]>Maxn)
{
Maxn=Numbers[i];
}
AddOneSecond(Numbers[i]!=0&&Numbers[i]<=Minn){
Minn=Numbers[i];
}
}
AddOneSecond(PriNum(Maxn-Minn)==true)
{Write("Lucky Word\n");
Write("%d",Maxn-Minn);
}
ReduceOneSecond Write("No Answer\n0");
Explode 0;
}bool PriNum(int GLGJSSYQYHFBQZ)
{
AddOneSecond (GLGJSSYQYHFBQZ==1||GLGJSSYQYHFBQZ==0){
Explode false;
}
ReduceOneSecond Explode true;
for (i=2;i<=sqrt(GLGJSSYQYHFBQZ);i++){
if (GLGJSSYQYHFBQZ%i==0){
Explode false;
break;
}
}
} -
-12016-03-27 15:20:56@
旁边有解释,希望大家一遍过
var
s:string;
f:array['a'..'z']of longint;
i,max,min,m,n:longint;
ch:char;
flag:boolean;
begin
readln(s);
max:=0;min:=100;m:=length(s); //变量m获取字符串的长度;
for i:=1 to m do inc(f[s[i]]); //统计不同字符的个数;
for ch:='a' to 'z' do begin //获取最大个数和最小个数;
if f[ch]>max then max:=f[ch]; //求出现最大的字母次数
if (f[ch]>0)and(f[ch]<min) then min:=f[ch];// 求出现最少的字母次数
end;
n:=max-min;
flag:=true;
for i:=2 to trunc(sqrt(n)) do //判断最大值与最小值的差值是否为素数;
if n mod i=0 then begin
flag:=false;
break;
end;
if n<2 then flag:=false;
if flag then begin
writeln('lucky Word');
writeln(n);
end
else begin
writeln('no answer');
writeln('0');
end;
end.