Luogu P1200 [USACO1.1] Your UFO is here, p1200usaco1.1

Source: Internet
Author: User

Luogu P1200 [USACO1.1] Your UFO is here, p1200usaco1.1
Description

As we all know, there is a UFO behind every comet. These UFOs often collect loyal supporters on the earth. Unfortunately, they can only bring a group of supporters to each trip. Therefore, they need to use a smart solution to let these groups know in advance who will be taken away by the comet. They named each comet and used these names to determine whether the group was the specific group that was taken away (who did you think gave the comet the name ?). The details about how to match them will be shown below. Your task is to write a program and decide whether the group can be taken away by the UFO behind the comet through the group name and the comet name.

The group name and comet name are converted into A number in the following way: the final number is the product of all the letters in the name, where "A" is 1 and "Z" is 26. For example, the "USACO" group is 21*19*1*3*15 = 17955. If the group's number mod 47 is equal to the number mod 47 of the comet, you have to tell the group that it is ready to be taken away! (Remember that "a mod B" is the remainder of a divided by B; 34 mod 10 equals 4)

Write a program, read the comet name and group name, and figure out whether the two names can be used together. If the two names can be used together, output "GO"; otherwise, output "STAY ". Both the group name and the comet name are uppercase letters (no more than 6 letters) without spaces or punctuation ).

Input/Output Format

Input Format:

 

Row 3: a string of 1 to 6 upper case, indicating the name of the comet.

Row 2nd: a string of 6 to 1 in upper case, indicating the name of the team.

 

Output Format:

 

Input and Output sample input sample #1: Copy
COMETQHVNGAT
Output example #1: Copy
GO
Input example #2: Copy
ABSTARUSACO
Output sample #2: Copy
STAY
Description

The question translation is from NOCOW.

USACO Training Section 1.1

 

Directly simulate

 

#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int MAXN=1e6+10;char a[MAXN],b[MAXN];int main(){    scanf("%s%s",a+1,b+1);    int la=strlen(a+1),lb=strlen(b+1);    long long int ansa=1,ansb=1;    for(int i=1;i<=la;i++) ansa*=(a[i]-'A'+1);    for(int i=1;i<=lb;i++) ansb*=(b[i]-'A'+1);    if(ansa%47==ansb%47) cout<<"GO";    else cout<<"STAY";    return 0;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.