描述


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
HVNGAT
GO
ABSTAR
USACO
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_(字符串+水题)的更多相关文章

  1. 1222: FJ的字符串 [水题]

    1222: FJ的字符串 [水题] 时间限制: 1 Sec 内存限制: 128 MB 提交: 92 解决: 20 统计 题目描述 FJ在沙盘上写了这样一些字符串: A1  =  “A” A2  =   ...

  2. 1001 字符串“水”题(二进制,map,哈希)

    1001: 字符串“水”题 时间限制: 1 Sec  内存限制: 128 MB提交: 210  解决: 39[提交][状态][讨论版] 题目描述 给出一个长度为 n 的字符串(1<=n<= ...

  3. 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题

    B - 大还是小? Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Description 输入两个实数,判断第一个数大 ...

  4. HDU ACM 1073 Online Judge -&gt;字符串水题

    分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...

  5. HDU4891_The Great Pan_字符串水题

    2014多校第五题,当时题面上的10^5写成105,我们大家都wa了几发,改正后我和一血就差几秒…不能忍 题目:http://acm.hdu.edu.cn/showproblem.php?pid=48 ...

  6. 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 ...

  7. 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 ...

  8. uva 10252 - Common Permutation 字符串水题

    题意:給定兩個小寫的字串a與b,請印出皆出現在兩字串中的字母,出現的字母由a~z的順序印出,若同字母出現不只一次,請重複印出但不能超過任一字串中出現的次數.(from Ruby兔) 很水,直接比较输出 ...

  9. hdu1106 字符串水题strtok()&&strchr()&&sscanf()+atoi()使用

    字符串的题目 用库函数往往能大大简化代码量 以hdu1106为例 函数介绍 strtok() 原型: char *strtok(char s[], const char *delim); 功能: 分解 ...

随机推荐

  1. Django信号的使用

    https://www.cnblogs.com/renpingsheng/p/7566647.html

  2. Spring+quartz cron表达式(cron手册官方)完美理解

    ------------------------------------- 15 17/1 14/3 * * ? 从每小时的17分15秒开始 每分钟的15秒执行一次14:17:15 ...14:59: ...

  3. Oracle 学习笔记(四)

    ​oracle表查询 使用逻辑操作符号  查询工资高于 500 或者是岗位为 MANAGER 的雇员,同时还要满足他们的姓名首字母为大写 J SELECT * FROM emp WHERE (sal ...

  4. 怎样安装Python3

    在浏览器地址栏输入https://www.python.org/ 打开Python官网 好了,安装完成了! 可以把安装路径C:\Users\Administrator\AppData\Local\Pr ...

  5. linux备忘录-系统服务daemon

    服务(daemon)及其分类 Linux中的服务被称为daemon(daemon是守护神,恶鬼的意思哦).这些daemon会常驻在内存当中,从而对我们的系统和任务等进行一些辅助性的工作.实际上,dae ...

  6. C#编译和运行原理

    关于编译与内存的关系,以及执行时内存的划分 1.所谓在编译期间分配空间指的是静态分配空间(相对于用new动态申请空间),如全局变量或静态变量(包括一些复杂类型的 常量),它们所需要的空间大小可以明确计 ...

  7. HDU 2139 Calculate the formula

    http://acm.hdu.edu.cn/showproblem.php?pid=2139 Problem Description You just need to calculate the su ...

  8. PS制作圆角透明图片

    方法一:利用“魔术棒橡皮工具”. 1. 点击“圆角矩形工具”,然后选中打开的背景图片,选中即可. 2.然后,按住“ctrl+enter”,所选边框变为虚线框,然后点击“ctrl+shift+i”反选( ...

  9. C# 获取方法所在的 命名空间 类名 方法名

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  10. Spring Data JPA 简单查询

    一.常用规则速查 1  And 并且2  Or  或3  Is,Equals 等于4  Between  两者之间5  LessThan 小于6  LessThanEqual   小于等于7  Gre ...