当前位置:网站首页>[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分享】云数据库如何定位慢查询
- RTP gb28181 document testing tool
- 【Try to Hack】john哈希破解工具
- canal同步mysql数据变化到kafka(centos部署)
- Ue5 small knowledge freezerendering view rendered objects in the cone
- RTP GB28181 文件测试工具
- How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
- 力扣(LeetCode)186. 翻转字符串里的单词 II(2022.07.05)
- Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
- Ue5 small knowledge points to enable the setting of lumen
猜你喜欢
View 工作流程
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Yyds dry inventory automatic lighting system based on CC2530 (ZigBee)
CertBot 更新证书失败解决
Is the mode of education together - on campus + off campus reliable
Fedora/REHL 安装 semanage
8. Static file
coreldraw2022新版本新功能介绍cdr2022
RTP GB28181 文件测试工具
RTP gb28181 document testing tool
随机推荐
Redis —— Redis In Action —— Redis 实战—— 实战篇一 —— 基于 Redis 的短信登录功能 —— Redis + Token 的共享 session 应用— 有代码
程序员在互联网行业的地位 | 每日趣闻
word封面下划线
[leetcode question brushing day 33] 1189 The maximum number of "balloons", 201. The number range is bitwise AND
web工程导入了mysql驱动jar包却无法加载到驱动的问题
满足多元需求:捷码打造3大一站式开发套餐,助力高效开发
也算是學習中的小總結
SharedPreferences 源码分析
Vulnerability discovery - vulnerability probe type utilization and repair of web applications
动态规划(树形dp)
Crawler notes: improve data collection efficiency! Use of proxy pool and thread pool
SQL注入漏洞(MSSQL注入)
Knowledge consolidation source code implementation 3: buffer ringbuffer
Programmers' position in the Internet industry | daily anecdotes
Hashlimit rate control
Uva1592 Database
canal同步mysql数据变化到kafka(centos部署)
The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry
Lagrange polynomial
Visio draws Tai Chi