hust 1062 Divisibility

题目描述

On the planet Zoop, numbers are represented in base 62, using the digits 0,
1, . . . , 9, A, B, . . . , Z, a, b, . . . , z where A (base 62) = 10 (base 10)
B (base 62) = 11 (base 10) . . . z (base 62) = 61 (base 10). Given the digit
representation of a number x in base 62, your goal is to determine if x is
divisible by 61.

输入

The input test file will contain multiple cases. Each test case will be given
by a single string containing only the digits ‘0’ through ‘9’, the uppercase
letters ‘A’ through ‘Z’, and the lowercase letters ’a’ through ’z’. All strings
will have a length of between 1 and 10000 characters, inclusive. The
end-of-input is denoted by a single line containing the word “end”, which should
not be processed.

输出

For each test case, print “yes” if the number is divisible by 61, and “no”
otherwise.

样例输入

1v3
2P6
IsThisDivisible
end

样例输出

yes
no
no

提示In the first example, 1v3 = 1 × 622 + 57 × 62 + 3 = 7381, which is
divisible by 61. In the second example, 2P6 = 2 × 622 + 25 × 62 + 6 = 9244,
which is not divisible by 61.

显然,提示是错误的,不过没关系,不影响我们做题


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;

int get_num(char x)
{
if (x>=‘0‘ && x<=‘9‘) return x-‘0‘;
if (x>=‘A‘ && x<=‘Z‘) return x-‘A‘+10;
if (x>=‘a‘ && x<=‘z‘) return x-‘a‘+36;
}

int main()
{
char str[10000+10];
int ans,temp;
while (scanf("%s",str)!=EOF && strcmp("end",str)!=0)
{
int L=strlen(str);
ans=0;
temp=1;
for (int i=L-1;i>=0;i--)
{
ans+=(get_num(str[i])*temp)%61;
ans=ans%61;
temp=(temp*62)%61;
}
if (ans%61) printf("no\n");
else printf("yes\n");
}
return 0;
}

作者 chensunrise

hust 1062 Divisibility,布布扣,bubuko.com

时间: 2024-08-06 16:06:19

hust 1062 Divisibility的相关文章

MySQL Last_SQL_Errno: 1062

一.环境描述 1. centos 6.6 2.mysql 5.6.25 3.基于gtid的复制 二.异常描述 误把从节点当成主节点插入一条数据,同一条数据在主.从节点插入都进行了一次插入操作,导致主键冲突,slave线程异常. 三.处理过程 1.查看报错信息 ([email protected]) [(none)]> show slave status\G; *************************** 1. row *************************** ......

HUST 1588 辗转数对

1588 - 辗转数对 时间限制:1秒 内存限制:128兆 155 次提交 27 次通过 题目描述 假设当前有一个数对(a, b),我们可以通过一步将这个数对变为一个新数对(a + b, b)或者是(a, a + b).初始的数对为(1, 1),你的任务是找到一个数字k,即通过最少的步数使得这个数对中至少一个数字等于n. 输入 输入包括多组数据,每组数据包括一行,每行有一个整数n. 输出 每组数据输出一行,每行一个整数n. 样例输入 5 3 样例输出 3 2 提示 第一个样例的方法是 (1,1)

HUST 1698 - 电影院 组合数学 + 分类思想

http://acm.hust.edu.cn/problem/show/1698 题目就是要把一个数n分成4段,其中中间两段一定要是奇数. 问有多少种情况. 分类, 奇数 + 奇数 + 奇数 + 奇数 奇数 + 奇数 + 奇数 + 偶数 偶数 + 奇数 + 奇数 + 奇数 偶数 + 奇数 + 奇数 + 偶数 然后奇数表达成 2 * a - 1这个样子,就能列出方程. 然后就是类似于解a1 + a2 + a3 + a4 = x的问题了. #include <cstdio> #include &l

HDU 3335 Divisibility(DLX可重复覆盖)

Problem Description As we know,the fzu AekdyCoin is famous of math,especially in the field of number theory.So,many people call him "the descendant of Chen Jingrun",which brings him a good reputation. AekdyCoin also plays an important role in th

HUST 1017 - Exact cover (Dancing Links 模板题)

1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is a selection of rows such that every column has a 1 in exactly one of the selected rows. Try to find o

勇士出征[HUST 1439]

勇士出征[HUST 1439] 时间1000ms,内存64MB 第十届"北大青鸟"杯浙江师范大学程序设计竞赛 这道题跟UVA-12100是一样的题目.我这里用的是STL的双端队列deque容器配合优先队列priority_queue,写起来会比较轻松:依次将输入压入队列,然后不断扫描队列,符合最大优先级的(优先队列的顶部元素)将其送出,而不再压入队尾.直到找到符合自己的标记的为止. 当然这道题也有用数组使用滚雪球的方式实现的,也就是开一个大的数组,每次将元素后挪时,直接将其放在数组末尾

poj 1745 Divisibility

Divisibility Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%lld & %llu Description Consider an arbitrary sequence of integers. One can place + or - operators between integers in the sequence, thus deriving different arithmetical expr

ERROR 1062 (23000): Duplicate entry &#39;0&#39; for key &#39;PRIMARY&#39;

OS: centos 6.3DB: 5.5.14 测试创建yoon测试表,没有主键,没有索引,基础数据内容如下: mysql> select * from yoon;+----+----------+------+| id | name | user |+----+----------+------+| 1 | \""##!aa | NULL || 2 | z2 | NULL || 3 | z3 | NULL || 4 | z4 | NULL || 5 | z5 | NULL |

UVALive 2659+HUST 1017+ZOJ 3209 (DLX

UVALive 2659 题目:16*16的数独.试了一发大白模板. /* * @author: Cwind */ //#pragma comment(linker, "/STACK:102400000,102400000") #include <iostream> #include <map> #include <algorithm> #include <cstdio> #include <cstring> #include