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 ...
随机推荐
- GIT版本管理工具教程
目录 GIT版本管理工具教程 一 Git初始化 二 简单指令使用 基本操作 简单总结 三 Git进阶 Git三大区域 Git回滚 Git分支 Git工作流 四 Github代码管理仓库 第一步:注册G ...
- JavaScript BOM Cookie 的用法
JavaScript Cookie Cookie是计算机上存储在小文本文件中的数据.当Web服务器将网页发送到浏览器时,连接将关闭,服务器将忘记用户的所有内容.发明Cookie是为了解决“如何记住用户 ...
- vue项目打包经验
[Element自带的图标不显示]打开 build/utils.js 文件,在如下位置添加 publicPath: '../../' [ElementUI的el-main组件默认会有padding=2 ...
- 剑指offer 8:旋转数组的最小数字
题目描述 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素.例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转 ...
- python 之serial、pyusb 使用开发
说明:本次是在windows 系统操作实现的. serial 使用场景,获取得力扫码枪的扫码数据,该扫码枪支持三种通讯接口设置,如下图 即插即用的是 USB-KBW功能,插上去即可获取扫码数据,第二种 ...
- Python3字典排序
创建一个字典 dict1={'a':2,'b':3,'c':8,'d':4} 1.分别取键.值 取字典的所有键,所有的值,利用dict1.keys(),dict1.vaules(), 由于键,值有很多 ...
- linux 使用indent格式化代码
indent是一个代码整理工具,能够方便快速的将代码格式化. 这是我较习惯的代码风格,网上还有很多其他的 参数: -nbad -bap -bbo -nbc -br -brs -c33 -cd33 -n ...
- Github实战测试情况
测试情况 很久没有熬夜测试程序了,经过测试,没有复现功能的有echo.葫芦娃.火鸡堂.那周余嘉熊掌将得队.为了交项目而干杯.修!咻咻!.云打印和追光的人.据汪老师反应在现场实践课程中大都能实现的,公平 ...
- centos虚拟机 与主机同步时间
同步系统时间: yum install ntp ntpdate cn.pool.ntp.org ntpdate 0.centos.pool.ntp.org rm /etc/localtime ln - ...
- zzPony.ai 的基础架构挑战与实践
本次分享将从以下几个方面介绍: Pony.ai 基础架构做什么 车载系统 仿真平台 数据基础架构 其他基础架构 1. Pony.ai 基础架构 首先给大家介绍一下 Pony.ai 的基础架构团队做什么 ...