UVA 10924 Prime Words 题解
Prime Words
A prime number is a number that has only two divisors: itself and the number one. Examples of prime
numbers are: 1, 2, 3, 5, 17, 101 and 10007.
In this problem you should read a set of words, each word is composed only by letters in the range
a-z and A-Z. Each letter has a specic value, the letter a is worth 1, letter b is worth 2 and so on until
letter z that is worth 26. In the same way, letter A is worth 27, letter B is worth 28 and letter Z is worth
52.
You should write a program to determine if a word is a prime word or not. A word is a prime word
if the sum of its letters is a prime number.
Input
The input consists of a set of words. Each word is in a line by itself and has L letters, where 1 L 20.
The input is terminated by enf of le (EOF).
Output
For each word you should print: `It is a prime word.', if the sum of the letters of the word is a
prime number, otherwise you should print: `It is not a prime word.'.
Sample Input
UFRN
contest
AcM
Sample Output
It is a prime word.
It is not a prime word.
It is not a prime word.
题意:给定一个串,在a~z对应1~26,A~Z对应1+26~26+26的情况下计算这个串的数值,如果这个数值是素数,输出“It is a prime word.”否则输出“It is not a prime word.”。
分析:水题,直接上代码。
#include<bits/stdc++.h>
using namespace std;
map<char,int> book;
bool u[];
void ass()
{
memset(u,true,sizeof(u));
for(int i=;i<=;i++)
{
if(u[i])
{
for(int j=;j<=;j++)
{
if(j*i>) break;
u[j*i]=false;
}
}
}
}
void pre()
{
for(char ch='a';ch<='z';ch++)
{
book[ch]=ch-'a'+;
}
for(char ch='A';ch<='Z';ch++)
{
book[ch]=ch-'A'++;
}
}
int main()
{
//freopen("input.txt","r",stdin);
pre();
ass();
char s[];
while(~scanf("%s",s))
{
int len=strlen(s);
int tmp=;
for(int i=;i<len;i++)
{
tmp+=book[s[i]];
}
if(u[tmp]) printf("It is a prime word.\n");
else printf("It is not a prime word.\n");
}
return ;
}
UVA 10924 Prime Words 题解的更多相关文章
- UVA - 524 Prime Ring Problem(dfs回溯法)
UVA - 524 Prime Ring Problem Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & % ...
- CF912E Prime Gift题解(搜索+二分答案)
CF912E Prime Gift题解(搜索+二分答案) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1314956 洛谷题目链接 $ $ CF题目 ...
- UVa 524 Prime Ring Problem(回溯法)
传送门 Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbe ...
- UVA 10200 Prime Time 水
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 10200 Prime Time【暴力,精度】
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- uva 524 prime ring problem——yhx
Prime Ring Problem A ring is composed of n (even number) circles as shown in diagram. Put natural ...
- Uva 552 Prime Ring Problem(dfs)
题目链接:Uva 552 思路分析:时间限制为3s,数据较小,使用深度搜索查找所有的解. 代码如下: #include <iostream> #include <string.h&g ...
- UVA 10140 - Prime Distance(数论)
10140 - Prime Distance 题目链接 题意:求[l,r]区间内近期和最远的素数对. 思路:素数打表,打到sqrt(Max)就可以,然后利用大的表去筛素数.因为[l, r]最多100W ...
- UVa 524 Prime Ring Problem(DFS , 回溯)
题意 把1到n这n个数以1为首位围成一圈 输出全部满足随意相邻两数之和均为素数的全部排列 直接枚举排列看是否符合肯定会超时的 n最大为16 利用回溯法 边生成边推断 就要快非常多了 #inc ...
随机推荐
- CTF挑战赛丨网络内生安全试验场第一季答题赛火热开启
前期回顾:挑战世界级“人机大战”,更有万元奖金等你来拿 网络内生安全试验场自上线以来,受到了业内的极大重视与关注. 自9月2日报名通道开启后,报名量更是持续高升,上百名精英白帽踊跃报名. 至此,网络内 ...
- curl tftp libcurl 功能使用
#include <curl/curl.h> static size_t read_callback(void *ptr, size_t size, size_t nmemb, void ...
- Finished with error: ProcessException: Process "D:\FlutterAPP\flutter_appfive\android\gradlew.bat" exited abnormally:
在使用Flutter进行开发是遇到这样一个问题 Finished with error: ProcessException: Process "D:\FlutterAPP\flutter_a ...
- Android Activity之间的数据传递
1.向目标Activity传递数据: Intent intent=new Intent(this,Main2Activity.class); //可传递多种类型的数据 intent.putExtra( ...
- Java使用MD5加密算法,实现等登陆功能
Java实现MD5加密 为了保护有些数据,就需要采取一些手段来进行数据的加密,防止被别人破解. MD5简介 md5的全称是md5信息摘要算法(英文:MD5 Message-Digest Algorit ...
- centos7 升级php7 添加配置epel源 报错:Cannot retrieve metalink for repository: epel. Please verify its path and try again
文章来自:循序渐渐linux:基础知识 一书 7.3章LAMP服务器搭建 日常故障 centos上好多软件升级需要配置epel源 其中有一点小插曲 需要手动更改 1.很多时候,对PHP环境要求较新的版 ...
- flask的request如何获取参数
1.request.form.get("key", type=str, default=None) 获取表单数据 2.request.args.get("key" ...
- Linux下JDK中文字体乱码
java生成图片的时候用到字体,但是liunx系统没有这些字体需要把C:\Windows\Fonts 上传到/usr/local/jdk1.8.0_171/jre/lib/fonts 重启tomcat ...
- 【使用篇二】SpringBoot整合Filter(2)
两种方式: 通过注解扫描完成 Filter 组件的注册 通过方法完成 Filter 组件的注册 一.通过注解扫描完成 Filter 组件的注册 1. 编写Filter类 /** * SpringBoo ...
- electron自定义桌面应用的外观
1. 控制应用视窗大小 构建桌面应用时,我们要考虑我们的应用程序需要如何让用户来使用,那么我们需要提供一个视窗,那么该视窗可以最大化展示,也可以最小化展示,当然我们也希望可以全屏运行. 在electr ...