P1125 笨小猴

原题地址

思路

读入,处理maxn和minn,一个判断(筛表法)maxx-minn是不是质数,再进行输出。


#include<bits/stdc++.h>
using namespace std;
char s[101];
int b[101],sum[101],k;
bool c[101];
bool f[300];
int cmp(int x,int y)                      
{
    if(x>y) return 1;
    else return 0;
}
int main(){
    f[1]=true;
    f[0]=true;
    for(int i=2;i*i<=200;i++){
        for(int j=i;j<=200/i;j++)
            f[i*j]=true;
    }//筛表
    cin>>s;
    int len=strlen(s);
    for(int i=0;i<len;i++)
        b[i+1]=s[i];  
    for(int i=1;i<=len;i++)//遍历字符串
      if(c[b[i]]==0)
       {
        for(int j=i;j<=len;j++)
         if(b[i]==b[j]) 
          sum[i]++;                       
        c[b[i]]=1; 
        k++;    
       }//统计maxn和minn。sum[1]是maxn,sum[2]是minn。
    sort(sum+1,sum+1+len,cmp);
    if(f[sum[1]-sum[k]]==false){
        cout<<"Lucky Word"<<endl<<sum[1]-sum[k];
    } else{
        cout<<"No Answer"<<endl<<0;
    }//输出
    return 0;
}

结束了………………

猜你喜欢

转载自www.cnblogs.com/zhouxuanbodl/p/10384027.html