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 题解的更多相关文章

  1. UVA - 524 Prime Ring Problem(dfs回溯法)

    UVA - 524 Prime Ring Problem Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & % ...

  2. CF912E Prime Gift题解(搜索+二分答案)

    CF912E Prime Gift题解(搜索+二分答案) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1314956 洛谷题目链接 $     $ CF题目 ...

  3. UVa 524 Prime Ring Problem(回溯法)

    传送门 Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbe ...

  4. UVA 10200 Prime Time 水

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  5. UVA 10200 Prime Time【暴力,精度】

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  6. uva 524 prime ring problem——yhx

      Prime Ring Problem  A ring is composed of n (even number) circles as shown in diagram. Put natural ...

  7. Uva 552 Prime Ring Problem(dfs)

    题目链接:Uva 552 思路分析:时间限制为3s,数据较小,使用深度搜索查找所有的解. 代码如下: #include <iostream> #include <string.h&g ...

  8. UVA 10140 - Prime Distance(数论)

    10140 - Prime Distance 题目链接 题意:求[l,r]区间内近期和最远的素数对. 思路:素数打表,打到sqrt(Max)就可以,然后利用大的表去筛素数.因为[l, r]最多100W ...

  9. UVa 524 Prime Ring Problem(DFS , 回溯)

    题意  把1到n这n个数以1为首位围成一圈  输出全部满足随意相邻两数之和均为素数的全部排列 直接枚举排列看是否符合肯定会超时的  n最大为16  利用回溯法 边生成边推断  就要快非常多了 #inc ...

随机推荐

  1. Python如何实现单例模式?其他23中设计模式python如何实现?

    单例模式主要有四种方法:new.共享属性.装饰器.import. # __ new__方法: class Singleton(object): def __new__(cls, *args, **kw ...

  2. python3 用户名和密码三次错误

    一.需求 1)密码输错超过三次进行锁定: 2)如果用户名在锁定文件中提示错误: 二.流程图 三.代码 # Aduthor:CCIP-Ma import sys f=open("passwor ...

  3. 使用Debug Diagnostic Tool排除内存泄漏故障

    在我之前的博文中(SQL Server内存泄漏),我解释了如何使用“!heap”命令识别哪个模块泄漏了内存.有时我们使用“!d”命令来找到模型或者使用搜索内存命令(s)不能通过显示内存找到原因. 在这 ...

  4. ios 点击webview获取图片url (js交互)

    加手势 -(void)handleSingleTap:(UITapGestureRecognizer *)sender { CGPoint pt = [sender locationInView:_c ...

  5. ios-tableview加载卡顿的解决方案

    参考文章:http://www.cocoachina.com/articles/11968 总结: 提前计算并缓存好高度(布局),因为heightForRowAtIndexPath:是调用最频繁的方法 ...

  6. 多线程学习笔记(三) BackgroundWorker 暂停/继续

    BackgroundWorker bw; private ManualResetEvent manualReset = new ManualResetEvent(true); private void ...

  7. Centos7安装和配置Tomcat8

    第一步:下载Tomcat8压缩包 进入 http://tomcat.apache.org/download-80.cgi 下载tar.gz压缩包 第二步:用xshell工具把压缩包上传到/home/d ...

  8. 安装教程-VMware 12 安装企业级 CentOS 7.6

    企业级 CentOS 7.6 系统的安装 1.实验描述 在虚拟机中,手动安装 CentOS 7.6 操作系统,为学习 Linux 提供平台,因此,有的参数有些差异,请勿较真. 2.实验环境 物理机系统 ...

  9. scanf的返回值

    参考这个博客,https://blog.csdn.net/sinat_40936062/article/details/84348021 #include<stdio.h> int mai ...

  10. 201871010106-丁宣元 《面向对象程序设计(java)》第八周学习总结

    201871010106-丁宣元 <面向对象程序设计(java)>第八周学习总结 正文开头: 项目 内容 这个作业属于哪个课程 https://home.cnblogs.com/u/nwn ...