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. Vert.x HTTP 服务器与客户端

    编写HTTP 服务器与客户端 Vert.x让编写非阻塞的HTTP 服务器与客户端变得非常轻松. 创建HTTP 服务器 缺省状况: HttpServer server = vertx.createHtt ...

  2. fetch和XMLHttpRequest

    fetch和XMLHttpRequest 如果看网上的fetch教程,会首先对比XMLHttpRequest和fetch的优劣,然后引出一堆看了很快会忘记的内容(本人记性不好).因此,我写一篇关于fe ...

  3. Windows Socket知识总结

     目录 0 理解Socket 1 WinSock API 2 阻塞socket 3 非阻塞Socket 4 套接字IO模型  4.1 套接字IO模型:select(选择)  4.2 套接字IO模型:W ...

  4. logstash 入门篇

    场景介绍 基于分布式集群海量日志数据,且分布在不同的服务器上,日志的采集以及可视化是需要我们解决的问题.ELK就是这么一个方案,当然我们这里主要讲解logstash安装配置和基础语法. ELK帮我们解 ...

  5. SimpleTagSupport 获取request、session

    开发jsp系统时,我们经常会用到tag来写java的逻辑代码,一般会继承两个类,一个是SimpleTagSupport,另一个是TagSupport,由于TagSupport书写配置比较复杂(我个人才 ...

  6. Oracle 11g R2 Sample Schemas 安装

    最近准备对之前学习SQL*Loader的笔记进行整理,希望通过官方文档中的示例学习(Case Studies)来进行,但是官方文档中示例学习相关的脚本文件在数据库软件安装完成之后默认并没有提供,而是整 ...

  7. C语言的暂停

    #include<stdio.h> int main(void) { printf("Hello, World!\n"); system("pause&quo ...

  8. Ansible 自动化运维工具

    Ansible 自动化运维工具 Ansible是什么? Ansible是一个"配置管理工具"也是一个"自动化运维工具" Ansible 作用: Ansible是 ...

  9. Flask框架之功能详解

    1|0浏览目录 配置文件 路由系统 视图 请求相关 响应 模板渲染 session 闪现 中间件 蓝图(blueprint) 特殊装饰器 1|1配置文件 知识点 给你一个路径 "settin ...

  10. 201871010132--张潇潇--《面向对象程序设计(java)》第十二周学习总结

    博文正文开头格式:(2分) 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.co ...