Section 1.1 Your Ride Is Here
Your Ride Is Here
It is a well-known fact that behind every good comet is a UFO. TheseUFOs often come to collect loyal supporters from here on Earth.Unfortunately, they only have room to pick up one group of followers oneach trip. They do, however, let the groups know ahead
of time whichwill be picked up for each comet by a clever scheme: they pick a namefor the comet which, along with the name of the group, can be used todetermine if it is a particular group's turn to go (who do you thinknames 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 acomet and then determines whether the group should go with the UFO behindthat comet.
Both the name of the group and the name of the comet are converted intoa number in the following manner: the final number is just the product ofall the letters in the name, where "A" is 1 and "Z" is26. 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 numbermod 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; 34mod 10 is 4.)
Write a program which reads in the name of the comet and the name ofthe group and figures out whether according to the above scheme the namesare a match, printing "GO" if they match and "STAY" ifnot. The names of the groups and the comets will be a string
of capitalletters 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 thewrong 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 linebut does not have a "return". Sometimes, programmers code forthe Windows paradigm of "return" followed by "newline"; don't dothat! 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 leaveenough room for a 'newline' (also notated as '\n') and an end ofstring 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), themission is 'GO'.
题意很简单,用A~Z表示1~26,然后字符串所表示的各个数字相乘的结果对47取余数,两个字符串处理的结果若一样,则输出GO, 否则输出STAY
#include <iostream>
#include <string>
#include <stdio.h>
/*
ID: ifayne1
LANG: C++
TASK: ride
*/ using namespace std; int main()
{
freopen("ride.in", "r", stdin);
freopen("ride.out", "w", stdout);
string s1, s2;
cin >> s1;
cin >> s2;
int k1 = s1.length();
int k2 = s2.length();
long long sum1 = 1, sum2 = 1;
for ( int i=0; i<k1; i++ )
sum1 *= (s1[i] - 'A' + 1);
for ( int i=0; i<k2; i++ )
sum2 *= (s2[i] - 'A' + 1); if ( sum1 % 47 == sum2 % 47 ) cout << "GO" << endl;
else cout << "STAY" << endl; return 0;
}
Section 1.1 Your Ride Is Here的更多相关文章
- USACO Section 1.1 Your Ride Is Here 解题报告
题目 问题描述 将字符串转变为数字,字母A对应的值为1,依次对应,字母Z对应的值为26.现在有一个字符串,将其中的每个字符转变为数字之后进行累乘,最终的结果对47求余数. 题目给你两个字符串,其中的字 ...
- USACO Section 1.1-1 Your Ride Is Here
USACO 1.1-1 Your Ride Is Here 你的飞碟在这儿 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...
- USACO Section 1.1PROB Your Ride Is Here
题目传送门 不能提交哦 http://www.nocow.cn/index.php/Translate:USACO/ride /* ID: jusonal1 PROG: ride LANG: C+ ...
- USACO Training Section 1.1 Your Ride Is Here
题目描述 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支持者.因此,他们要用一种聪明的方案让这些小组提前知道谁会被彗星带走 ...
- USACO Training刷题记录 By cellur925
Section 1.1 Your Ride Is Here 貌似没啥可说 Greedy Gift Givers 上来就想stl map映射,有两个坑:如果送给别人的人数为0,那么需要特判一下,防止整数 ...
- 洛谷 P1200 [USACO1.1]你的飞碟在这儿Your Ride Is He…【字符串+模拟】
P1200 [USACO1.1]你的飞碟在这儿Your Ride Is He… 题目描述 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都 ...
- keil MDK error: L6236E: No section matches selector - no section 错误
今天板子刚到,新建的第一个工程就报错了. .\Objects\cse.sct(7): error: L6236E: No section matches selector - no section t ...
- 【代码笔记】iOS-一个tableView,两个section
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- gcc/linux内核中likely、unlikely和__attribute__(section(""))属性
查看linux内核源码,你会发现有很多if (likely(""))...及if (unlikely(""))...语句,这些语句其实是编译器的一种优化方式,具 ...
随机推荐
- object覆盖的div解决办法
最近做个web项目,因为里面有个<object>的插件,弹出<div>对话框会被其遮盖,我做了个<iframe>标签,在弹框时,把<object>覆盖掉 ...
- php产生随机字符串
/** * 产生随机字符串 * * @param int $length 输出长度 * @param string $chars 可选的 ,默认为 0123456789 * @return strin ...
- jquery提交form表单插件jquery.form.js
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- RabbitMQ系列教程之四:路由(Routing)
(使用Net客户端)在上一个教程中,我们构建了一个简单的日志系统,我们能够向许多消息接受者广播发送日志消息.在本教程中,我们将为其添加一项功能 ,这个功能是我们将只订阅消息的一个子集成为可能. 例如, ...
- [命令行] curl查询公网出口IP
转载:http://blog.csdn.net/orangleliu/article/details/51994513 不管是在家里还是办公室,或者是公司的主机,很多时候都是在内网中,也就是说很多都是 ...
- Teacher implements java.io.Serializable
package JBJADV003; public class Teacher implements java.io.Serializable{ private String name; privat ...
- .net core建站踩坑记录
系统:win10 VS版本:2017 .NET Core 版本: 1.1 零.读取配置文件 参考:http://www.tuicool.com/articles/QfYVBvi 此版本无需添加其他组件 ...
- 关于JAVA正则匹配空白字符的问题
今天遇到一个字符串,怎么匹配空格都不成功!!! 我把空格复制到test.properties文件 显示“\u3000” ,这是什么? 这是全角空格!!! 查了一下 \s 不支持全角 1.& ...
- WPF WebBrowser Memory Leak 问题及临时解决方法
首先介绍一下内存泄漏(Memory Leak)的概念,内存泄露是指程序中已动态分配的堆内存由于某种原因未释放或者无法释放,造成系统内存的浪费,导致程序运行速度减慢甚至系统崩溃等严重后果. 最近在使用W ...
- IDEA的热部署插件jrebel6.4.3离线安装版配置与破解
JRebel 介绍 IDEA上原生是不支持热部署的,一般更新了 Java 文件后要手动重启 Tomcat 服务器,才能生效,浪费不少生命啊.目前对于idea热部署最好的解决方案就是安装JRebel插件 ...