【字符串】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.

输入

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.

输出

A single line containing either the word "GO" or the word "STAY".

样例输入

COMETQ
HVNGAT

样例输出

GO

分析:按题意走呗,他说怎样就怎样~。

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
string a,b;
LL mul1,mul2;
void init(){
    cin>>a>>b;
    mul1=mul2=1;
}
void solve(){
    range(i,0,a.size()-1)mul1*=a[i]-‘A‘+1;
    range(i,0,b.size()-1)mul2*=b[i]-‘A‘+1;
    cout<<(mul1%47==mul2%47?"GO":"STAY")<<endl;
}
int main() {
    init();
    solve();
    return 0;
}

原文地址:https://www.cnblogs.com/Rhythm-/p/9326854.html

时间: 2024-10-31 07:25:12

【字符串】Your Ride Is Here的相关文章

USACO 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. 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, how

【USACO1.1.1】Your Ride Is Here

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

Your Ride Is Here

题解: 模拟. 将这两个字符串每一个字符所对应的数字相乘,在mod 47判断是否相同(注意:相同GO,不相同STAY). { ID:h1956701 LANG:PASCAL PROB:ride } var s1,s2:ansistring; function pd(s:ansistring):longint; var ans,i:longint; begin ans:=1; for i:=1 to length(s) do ans:=ans*(ord(s[i])-64)mod 47; exit(

UVA 156-Ananagrams(字符串排序按序输出无重复单词)

Ananagrams Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description  Ananagrams  Most crossword puzzle fans are used to anagrams--groups of words with the same letters in different orders--for example OPTS, SPO

USACO 1.1 Your Ride Is Here

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

UVA 156 Ananagrams 关于二维数组表示的字符串排序的问题

题目链接:UVA 156 Ananagrams  Ananagrams  Most crossword puzzle fans are used to anagrams--groups of words with the same letters in different orders--for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this attribute, no matter how

字符串模拟入门

如题(水题大集锦) 1.P1914 小书童——密码 直通 思路: 因为是循环的,所以我们进行%26即可 上代码: #include <iostream> #include <cstdio> using namespace std; const int Mod = 26; const char e[Mod] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v

USACO-Your Ride Is Here(你的飞碟在这儿)-Section1.2&lt;2&gt;

[英文原题] 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,

简单字符串

P1055 ISBN号码 题目描述 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括 99 位数字. 11 位识别码和 33 位分隔符,其规定格式如x-xxx-xxxxx-x,其中符号-就是分隔符(键盘上的减号),最后一位是识别码,例如0-670-82162-4就是一个标准的ISBN码.ISBN码的首位数字表示书籍的出版语言,例如 00 代表英语:第一个分隔符-之后的三位数字代表出版社,例如 670670 代表维京出版社:第二个分隔符后的五位数字代表该书在该出版社的编号:最后一位