USACO_1.1_Your_Ride_Is_Here_(字符串+水题)
描述
http://train.usaco.org/usacoprob2?a=y0SKxY0Kc2q&S=ride
给出两个由大写字母组成,长度不大于$6$的字符串.
将字符串中的各字母的字典序数相乘,最后对$47$取模,比较两个字符串的结果是否相同.
Your Ride Is Here
It is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect loyal supporters from here on Earth. Unfortunately, they only have room to pick up one group of followers on each trip. They do, however, let the groups know ahead of time which will be picked up for each comet by a clever scheme: they pick a name for the comet which, along with the name of the group, can be used to determine if it is a particular group's turn to go (who do you think names the comets?). The details of the matching scheme are given below; your job is to write a program which takes the names of a group and a comet and then determines whether the group should go with the UFO behind that comet.
Both the name of the group and the name of the comet are converted into a number in the following manner: the final number is just the product of all the letters in the name, where "A" is 1 and "Z" is 26. For instance, the group "USACO" would be 21 * 19 * 1 * 3 * 15 = 17955. If the group's number mod 47 is the same as the comet's number mod 47, then you need to tell the group to get ready! (Remember that "a mod b" is the remainder left over after dividing a by b; 34 mod 10 is 4.)
Write a program which reads in the name of the comet and the name of the group and figures out whether according to the above scheme the names are a match, printing "GO" if they match and "STAY" if not. The names of the groups and the comets will be a string of capital letters with no spaces or punctuation, up to 6 characters long.
Examples:
Input | Output |
COMETQ |
GO |
ABSTAR |
STAY |
PROGRAM NAME: ride
This means that you fill in your header with:
PROG: ride
WARNING: You must have 'ride' in this field or the
wrong test data (or no test data) will be used.
INPUT FORMAT
Line 1: | An upper case character string of length 1..6 that is the name of the comet. |
Line 2: | An upper case character string of length 1..6 that is the name of the group. |
NOTE: The input file has a newline at the end of each line
but does not have a "return". Sometimes, programmers code for
the Windows paradigm of "return" followed by "newline"; don't do
that! Use simple input routines like "readln" (for Pascal) and,
for C/C++, "fscanf" and "fid>>string".
NOTE 2: Because of the extra characters, be sure to leave
enough room for a 'newline' (also notated as '\n') and an end of
string character ('\0') if your language uses it (as C and C++ do).
This means you need eight characters of room instead of six.
SAMPLE INPUT (file ride.in)
COMETQ
HVNGAT
OUTPUT FORMAT
A single line containing either the word "GO" or the word "STAY".
SAMPLE OUTPUT (file ride.out)
GO
OUTPUT EXPLANATION
Converting the letters to numbers:
C | O | M | E | T | Q | |
3 | 15 | 13 | 5 | 20 | 17 | |
H | V | N | G | A | T | |
8 | 22 | 14 | 7 | 1 | 20 |
then calculate the product mod 47:
3 * 15 * 13 * 5 * 20 * 17 = 994500 mod 47 = 27
8 * 22 * 14 * 7 * 1 * 20 = 344960 mod 47 = 27
Because both products evaluate to 27 (when modded by 47), the mission is 'GO'.
分析
没啥好分析的..
/*
TASK:ride
LANG:C++
*/ #include <bits/stdc++.h>
using namespace std; const int mod=, maxn=;
int x,y;
char a[maxn],b[maxn]; int main(){
freopen("ride.in","r",stdin);
freopen("ride.out","w",stdout);
scanf("%s%s",a,b);
x=y=;
for(int i=;i<maxn;i++){
if(a[i]) x=(x*(a[i]-'A'+))%mod;
if(b[i]) y=(y*(b[i]-'A'+))%mod;
}
x==y ? puts("GO") : puts("STAY");
return ;
}
USACO_1.1_Your_Ride_Is_Here_(字符串+水题)的更多相关文章
- 1222: FJ的字符串 [水题]
1222: FJ的字符串 [水题] 时间限制: 1 Sec 内存限制: 128 MB 提交: 92 解决: 20 统计 题目描述 FJ在沙盘上写了这样一些字符串: A1 = “A” A2 = ...
- 1001 字符串“水”题(二进制,map,哈希)
1001: 字符串“水”题 时间限制: 1 Sec 内存限制: 128 MB提交: 210 解决: 39[提交][状态][讨论版] 题目描述 给出一个长度为 n 的字符串(1<=n<= ...
- 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题
B - 大还是小? Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Description 输入两个实数,判断第一个数大 ...
- HDU ACM 1073 Online Judge ->字符串水题
分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...
- HDU4891_The Great Pan_字符串水题
2014多校第五题,当时题面上的10^5写成105,我们大家都wa了几发,改正后我和一血就差几秒…不能忍 题目:http://acm.hdu.edu.cn/showproblem.php?pid=48 ...
- Codeforces Round #309 (Div. 2) B. Ohana Cleans Up 字符串水题
B. Ohana Cleans Up Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/pr ...
- Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题
A. Kyoya and Photobooks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- uva 10252 - Common Permutation 字符串水题
题意:給定兩個小寫的字串a與b,請印出皆出現在兩字串中的字母,出現的字母由a~z的順序印出,若同字母出現不只一次,請重複印出但不能超過任一字串中出現的次數.(from Ruby兔) 很水,直接比较输出 ...
- hdu1106 字符串水题strtok()&&strchr()&&sscanf()+atoi()使用
字符串的题目 用库函数往往能大大简化代码量 以hdu1106为例 函数介绍 strtok() 原型: char *strtok(char s[], const char *delim); 功能: 分解 ...
随机推荐
- 「日常训练」「小专题·USACO」 Ski Course Design (1-4)
题目 以后补 分析 mmp这题把我写蠢哭了 我原来的思路是什么呢? 每轮找min/max,然后两个决策:升min/降max 像这样子dfs找最优,然后花式剪枝 但是一想不对啊,这才1-4,哪有那么复杂 ...
- Ubuntu-C++环境设置
在学习C++,顺便想熟悉一下Linux下开发 所以就开始搭建Linux环境 第一步就是下载虚拟机和Ubuntu 虚拟机 vm 12.1 Ubuntu 16 VM安装省略 Ubuntu安装省略 下面是我 ...
- 2016弱校联盟十一专场10.3 We don't wanna work!
能把 not working now 写成 not working hard now 还查一晚上也是没谁了 我的做法是维护两个set 分别是前20% 和后80% #include<iostrea ...
- CSS3 : box-shadow
box-shadow 用于设置边框阴影,语法: box-shadow: h-shadow v-shadow blur spread color inset; -moz-box-shadow: h-sh ...
- 剑指offer-合并两个排序链表16
题目描述 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则. class Solution: # 返回合并后列表 def Merge(self, pHead1 ...
- 剑指offer-变态跳台阶09
题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级.求该青蛙跳上一个n级的台阶总共有多少种跳法. class Solution: def jumpFloorII(self, n ...
- LeetCode 33——搜索旋转排序数组
1. 题目 2. 解答 2.1. 方法一 直接进行二分查找,在判断查找方向的时候详细分类. 当 nums[mid] < target 时, 若 nums[left] <= nums[mid ...
- Jenkins的pipeline脚本中获取git代码变更用户名和email
// Get checkout output valuedef changeLogSets = checkout([$class: 'GitSCM', branches: [[name: '*/mas ...
- Python 异步编程笔记:asyncio
个人笔记,不保证正确. 虽然说看到很多人不看好 asyncio,但是这个东西还是必须学的.. 基于协程的异步,在很多语言中都有,学会了 Python 的,就一通百通. 一.生成器 generator ...
- Java——异常博客作业
本次任务地址 6. 为如下代码加上异常处理 6.1 改正代码,并增加如下功能.当找不到文件时,需提示用户找不到文件xxx,请重新输入文件名,然后尝试重新打开. 如果是其他异常则提示打开或读取文件失败! ...