1.1.1 Your Ride is here

Source: Internet
Author: User

Your Ride is here

It is a well-known fact, behind every good comet is a UFO. These UFOs often come to collect loyal supporters from this on Earth. Unfortunately, they only has a one-to-pick up-one group of followers on each trip. They do, however, let the groups know ahead of time which would 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 being used to determine if it's a particular group ' s turn t O Go (who does 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 G O with the UFO behind that comet.

Both the name of the group and the name of the comet is converted into a number in the following manner:the final number is just the product of the letters in the name, where ' A ' is 1 and ' Z ' is 26. For instance, the group "Usaco" would is 21 * 19 * 1 * 3 * 15 = 17955. If the group's number mod is the same as the comet's number mod, then you need to the group to get ready! (Remember that "a mod B" was the remainder left-over dividing a by B; MoD 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 AB Ove scheme the names is a match, printing "GO" if they match and "stay" if not. The names of the groups and the Comets is a string of capital letters with no spaces or punctuation, up to 6 characte RS Long.

Examples:

Input

Output

Cometq

Hvngat

GO

Abstar

Usaco

Stay

Program Name:ride

This means the your header with:

Prog:ride

WARNING: You must has ' ride ' in this field or the wrong test data (or no test data) would be used.

INPUT FORMAT

Line 1:

An upper case character string of length 1..6 this 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 and does not having 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 + +, "fscanf" and "fid>>string".

Note 2: Because of the extra characters, be-sure to leave enough-class for a ' newline ' (also notated as ' \ n ') and An end of string character (' + ') if your language uses it (as C and C + + do). This means you need eight characters of the hostel 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

< P class= "P4" >t

8

22

14

7

1

20

Then calculate the Product mod 47:

3 * * 5 * * + = 994500 MoD 47 = 27

8 * * 7 * 1 * = 344960 MoD 47 = 27

Because both products evaluate to [when modded by], the mission is ' GO '.

Code:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <fstream>5 using namespacestd;6 intMain ()7 {8Ofstream Fout ("Ride.out");9Ifstream Fin ("ride.in");Ten     Chars1[Ten],s2[Ten]; OneFin>>S1; AFin>>S2; -     intl1=strlen (S1); -     intL2=strlen (S2); the     intsum1=1, sum2=1; -      for(intI=0; i<l1;i++){ -Sum1*= (int) (s1[i]-'A'+1); -sum1%= -; +     } -      for(intI=0; i<l2;i++){ +Sum2*= (int) (s2[i]-'A'+1); Asum2%= -; at     } -     if(sum1==sum2) fout<<"GO"<<Endl; -     Elsefout<<"Stay"<<Endl; -     return 0; -}

1.1.1 Your Ride is here

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.