当前位置:网站首页>[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;
}
边栏推荐
- npm命令--安装依赖包--用法/详解
- word封面下划线
- 2328. Number of incremental paths in the grid graph (memory search)
- JVM garbage collector concept
- 我想问一下 按照现在mysql-cdc的设计,全量阶段,如果某一个chunk的binlog回填阶段,
- Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
- Selection sort
- Yyds dry inventory automatic lighting system based on CC2530 (ZigBee)
- 【HBZ分享】ArrayList的增删慢查询快的原因
- P3500 [POI2010]TES-Intelligence Test(二分&离线)
猜你喜欢
![[Zhao Yuqiang] deploy kubernetes cluster with binary package](/img/be/8710605c8da8d1553af974f0dc46bc.jpg)
[Zhao Yuqiang] deploy kubernetes cluster with binary package

coreldraw2022新版本新功能介绍cdr2022

Digital children < daily question> (Digital DP)
![[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
![[network] channel attention network and spatial attention network](/img/b5/5e746f0dd6badcf0714cae05fc6e82.jpg)
[network] channel attention network and spatial attention network

程序员在互联网行业的地位 | 每日趣闻

How to estimate the population with samples? (mean, variance, standard deviation)

Orm-f & Q object

Sqlserver query results are not displayed in tabular form. How to modify them

Programmers' position in the Internet industry | daily anecdotes
随机推荐
Bubble sort
Easyrecovery靠谱不收费的数据恢复电脑软件
ISP学习(2)
牛顿插值法
cdc 能全量拉去oracle 表嘛
Yyds dry goods inventory OSI & tcp/ip
Project manager, can you draw prototypes? Does the project manager need to do product design?
ETCD数据库源码分析——etcdserver bootstrap初始化存储
力扣(LeetCode)186. 翻转字符串里的单词 II(2022.07.05)
C'est un petit résumé de l'étude.
Introduction to hashtable
How to realize automatic playback of H5 video
Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
Supreme Court, judgment standard of divorce cases
How does vs change the project type?
Certbot failed to update certificate solution
Can Flink SQL read multiple topics at the same time. How to write in with
How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
SQL injection vulnerability (MSSQL injection)
Can CDC pull the Oracle table in full