当前位置:网站首页>[NOIP2008 提高组] 笨小猴
[NOIP2008 提高组] 笨小猴
2022-07-06 04:42:00 【Recurss】
题目描述
笨小猴的词汇量很小,所以每次做英语选择题的时候都很头疼。但是他找到了一种方法,经试验证明,用这种方法去选择选项的时候选对的几率非常大!
这种方法的具体描述如下:假设maxn是单词中出现次数最多的字母的出现次数,minn是单词中出现次数最少的字母的出现次数,如果maxn-minn是一个质数,那么笨小猴就认为这是个Lucky Word,这样的单词很可能就是正确的答案。
输入格式
一个单词,其中只可能出现小写字母,并且长度小于 100 100 100。
输出格式
共两行,第一行是一个字符串,假设输入的的单词是Lucky Word,那么输出“Lucky Word”,否则输出“No Answer”;
第二行是一个整数,如果输入单词是Lucky Word,输出maxn-minn的值,否则输出 0 0 0。
样例 #1
样例输入 #1
error
样例输出 #1
Lucky Word
2
样例 #2
样例输入 #2
olympic
样例输出 #2
No Answer
0
提示
【输入输出样例1解释】
单词error中出现最多的字母 r r r出现了 3 3 3次,出现次数最少的字母出现了 1 1 1次, 3 − 1 = 2 3-1=2 3−1=2, 2 2 2是质数。
【输入输出样例2解释】
单词olympic中出现最多的字母 i i i出现了 1 1 1次,出现次数最少的字母出现了 1 1 1次, 1 − 1 = 0 1-1=0 1−1=0, 0 0 0不是质数。
(本处原题面错误已经修正)
noip2008提高第一题
/* * @Description: To iterate is human, to recurse divine. * @Autor: Recursion * @Date: 2022-07-03 23:24:38 * @LastEditTime: 2022-07-03 23:46:08 */
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int mod = 1e9 + 7;
const int INF = 1e9 + 10;
const int N = 1e6;
bool sushu(int x)
{
if(x==0||x==1) return false;
if(x==2) return true;
for(int j=2;j*j<=x;j++)
{
if(x%j==0) return false;
}
return true;
}
int maxn,minn = INF;
string s;
int arr[N];
int sum[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s;
for(int i = 0;i < s.length();i ++){
sum[s[i] - 'a']++;//求每个字母出现个数
}
//求最大和最小值
for(int i=0;i<26;i++){
//遍历26个字母
if(sum[i]>maxn) maxn=sum[i];//比较maxn
if(sum[i]>0&&sum[i]<minn) minn=sum[i];//比较minn,只比较出现过的字母
}
int ans = maxn - minn;
if(sushu(ans))
cout << "Lucky Word" << endl << ans;
else
cout << "No Answer" << endl << 0;
return 0;
}
边栏推荐
- 【HBZ分享】ArrayList的增删慢查询快的原因
- How to realize automatic playback of H5 video
- C. The third problem
- Selection sort
- Redis —— Redis In Action —— Redis 实战—— 实战篇一 —— 基于 Redis 的短信登录功能 —— Redis + Token 的共享 session 应用— 有代码
- 牛顿插值法
- 麥斯克電子IPO被終止:曾擬募資8億 河南資產是股東
- Redis 排查大 key 的4種方法,優化必備
- Recommendation | recommendation of 9 psychotherapy books
- Word cover underline
猜你喜欢

Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill

CADD course learning (8) -- virtual screening of Compound Library

Easyrecovery reliable and toll free data recovery computer software
![[Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University](/img/22/ead74bc121a64910ef6ef374cd029b.png)
[Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University

Implementation of knowledge consolidation source code 1: epoll implementation of TCP server

比尔·盖茨晒18岁个人简历,48年前期望年薪1.2万美元

8. Static file

Visio draw fan

Fuzzy -- basic application method of AFL

Introduction to hashtable
随机推荐
Can CDC pull the Oracle table in full
View 工作流程
. Net interprocess communication
Postman断言
The value of two date types is subtracted and converted to seconds
Introduction to hashtable
Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
Project manager, can you draw prototypes? Does the project manager need to do product design?
Flink kakfa data read and write to Hudi
flink sql 能同时读多个topic吗。with里怎么写
Mysql database storage engine
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
Quatre méthodes de redis pour dépanner les grandes clés sont nécessaires pour optimiser
RTP GB28181 文件测试工具
Selection sort
English Vocabulary - life scene memory method
Programmers' position in the Internet industry | daily anecdotes
[leetcode question brushing day 33] 1189 The maximum number of "balloons", 201. The number range is bitwise AND
P2102 floor tile laying (DFS & greed)
How to estimate the population with samples? (mean, variance, standard deviation)