描述


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. FreeRTOS任务暂停和启动函数

    任务句柄 TaskHandle_t pump_task_handle = NULL; 任务的启动函数 if(eTaskGetState(pump_task_handle) != eRunning) v ...

  2. Clean Code 《代码整洁之道》前四章读书笔记

    第一章: 整洁的代码只做好一件事   减少重复代码   提高表达力   提早构建简单抽象   让营地比你来时更干净   第二章:有意义的命名 名副其实:如果名称需要注释来补充,就不算是名副其实.   ...

  3. 【个人训练】(POJ1276)Cash Machine

    最近的很多题解应该都是dp相关的了,emmm因为dp对我而言思考难度比较大,那么为了理顺自己的思路当然只能通过写blog整理了.愿我能成功搞定dp这个大关!(至少中等难度的dp要能够解决啊o(TヘTo ...

  4. #Spring实战第二章学习笔记————装配Bean

    Spring实战第二章学习笔记----装配Bean 创建应用对象之间协作关系的行为通常称为装配(wiring).这也是依赖注入(DI)的本质. Spring配置的可选方案 当描述bean如何被装配时, ...

  5. zabbix从入门到精通

    第1章 zabbix监控 1.1 为什么要监控 在需要的时刻,提前提醒我们服务器出问题了 当出问题之后,可以找到问题的根源   网站/服务器 的可用性 1.1.1 网站可用性 在软件系统的高可靠性(也 ...

  6. k8s第一个实例创建redis集群服务

    1.创建redis-master-controller.yaml apiVersion: v1 kind: ReplicationController metadata: name: redis-ma ...

  7. PhpStorm 配置IDE

    IDE => Xdebug => Apache(XAMPP) => Firefox + easist Xdebug 1>XAMPP停止apache服务;2>在安装目录下找 ...

  8. Hibernate配置实体类的属性

    Hibernate配置实体类的属性既可以在页面显示关联实体类的所有属性,在插入该属性时又可以只插入单一属性 private String companyCode; private CompanyEnt ...

  9. MySql动态生成SQL并执行

    场景:由于一些表中设计了一些冗余字段,因此在主表修改了该冗余字段的值得时候,需要动态更新在其他表中冗余字段的值 BEGIN #Routine body goes here... /*SQL语句变量*/ ...

  10. DPDK 网卡RSS(receive side scaling)简介

    网卡RSS(receive side scaling)简介 RSS是一种网卡驱动技术,能让多核系统中跨多个处理器的网络收包处理能力高效能分配.注意:由于同一个核的处理器超线程共享同一个执行引擎,这个效 ...