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. WPF控件模板(6)

    什么是ControlTemplate? ControlTemplate(控件模板)不仅是用于来定义控件的外观.样式, 还可通过控件模板的触发器(ControlTemplate.Triggers)修改控 ...

  2. .NET Core RabbitMQ探索(2)——RabbitMQ的Exchange

    实际上,RabbitMQ的生产者并不会直接把消息发送给队列,甚至生产者都不知道消息是否会被发送给一个队列.对于生产者而言,它们只能把消息发送到Exchange,一个Exchange所完成的工作相当简单 ...

  3. golang中,slice的几个易混淆点

    slice在golang中是最常用的类型,一般可以把它作为数组使用,但是比数组要高效呀.不过,我感觉这个东西用的不好坑太多了.还是需要了解下他底层的实现 slice的结构定义 type slice s ...

  4. C#和Java的对比

    C#和Java的对比 C#是微软公司在2000年6月发布的一种面向对象的高级程序设计语言:Java是Sun公司在1996年1月发布的一种面向对象的.平台独立的高级程序设计语言.它们是现在最流行的面向对 ...

  5. 【转载】Visual Studio2017中如何设置解决方案中的某个项目为启动项目

    在C#的应用程序开发过程中,一个完成的解决方案可能包含多个子项目,有时候需要设置某一个子项目为启动项目,在Visual Studio 2017集成开发工具中,设置解决方案中的某个项目为启动项目的操作方 ...

  6. vue-router简易的实现原理

    class VueRouter { constructor(options) { this.$options = options; this.routeMap = {}; // 路由响应式 this. ...

  7. 原生 JavaScript 代替 jQuery【转】

    目录 用原生JavaScript代替jQuery Query Selector CSS & Style DOM Manipulation Ajax Events Utilities Promi ...

  8. GCN 简单numpy实现

    `#参考:https://blog.csdn.net/weixin_42052081/article/details/89108966 import numpy as np import networ ...

  9. mysql dump备份 、 mysql还原操作练习

    1.备份mysql.dump 备份MySQL数据库的命令 mysqldump -h主机名 -u用户名 -p密码 数据库名字 > 备份的数据库名字.sql 例子: mysqldump -uroot ...

  10. Portainer

    docker search portainer docker pull portainer/portainer docker run -it \ --name prtainer \ -p 9000:9 ...