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); 功能: 分解 ...
随机推荐
- linux shell中读写操作mysql数据库
本文介绍了如何在shell中读写mysql数据库.主要介绍了如何在shell 中连接mysql数据库,如何在shell中创建数据库,创建表,插入csv文件,读取mysql数据库,导出mysql数据库为 ...
- 【数据库】 SQL SERVER 2014 实用新特性
[数据库] SQL SERVER 2014 实用新特性 官方链接 一. 内存优化表 大幅提高数据库性能,不过目前没有窗口化设计只能写语句 二. 索引增强
- 第九篇 Python数据类型之集合
集合 set 写在最前,必须要会的:1.长度len2.成员运算in和not in3.|合集4.&交集5.-差集6.^对称差集7.==8.父集:>,>= 9.子集:<,< ...
- linux ----- Vim进入和退出命令
Vim进入和退出命令 本来不想写任何关于vim的文章的,无奈我今天又忘记怎么退出vim了,常用命令是ESC,然后:wq(保存并退出),:q!(不保存并强制退出),i进入vim模式.另外还有其它 ...
- 九度OJ--Q1166
import java.text.DecimalFormat;import java.util.Scanner; /* * 题目描述: * 立方根的逼近迭代方程是 y(n+1) = y(n)*2/3 ...
- URAL 1736 Chinese Hockey(网络最大流)
Description Sergey and Denis closely followed the Chinese Football Championship, which has just come ...
- JavaScript Map数据结构
Array.prototype.remove = function (s) { for (var i = 0; i < this.length; i++) { if (s == this[i]) ...
- Linux 进程,线程,线程池
在linux内核,线程与进程的区别很小,或者说内核并没有真正所谓单独的线程的概念,进程的创建函数是fork,而线程的创建是通过clone实现的. 而clone与fork都是调用do_fork(),差异 ...
- java文件的I/O
[原创] java文件的I/O操作,简单来说就是向文件中写入数据以及从文件中读出数据,这是我们平日做的最多的操作,这里给出两种文件I/O操作,当然还有许多的操作方法,各种流的使用,可谓是高深莫测:不管 ...
- 健康领域今年开始井喷了,养老地产和私人医生这两个领域目测成为下一轮BAT在健康领域布局的竞争方向
医疗行业做了六年多的时间,今年到了井喷的阶段,腾讯先是入股了丁香园,然后又一亿美金融资挂号网,春雨医生获得5000万美元的C轮融资,这是要上市的节奏.. 从互联网战略上,健康网和医疗网都是做资料刚开始 ...