Usaco section 1.1: your ride is here

Source: Internet
Author: User
Document directory
  • Program name: Ride
  • Input Format
  • Sample input (File ride. In)
  • Output Format
  • Sample output (File ride. out)

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, CA N be used to determine if it is a particle 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 shocould 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" wocould 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
COMETQHVNGAT
Go
ABSTARUSACO
Stay
Program name: rideinput 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 ".

Sample input (File ride. In)
COMETQHVNGAT    
Output Format

A single line containing either the word "go" or the word "Stay ".

Sample output (File ride. out)
GO
 

As we all know, every comet has a UFO ). These UFO are often here to find loyal supporters. Unfortunately, they can only take part of their supporters each trip. However, they always use a smart solution to let the Group know in advance who will be taken to which comet: They give each comet a name and each group a name, in this way, you can decide whether it is your turn to the group (who do you think will name huixing ?). The details of the matching scheme are as follows. Your task is to compile a program with the group name and huixing name, and then decide whether the group should be taken to huixing by UFO.
The group name and huixing name are converted to numbers through the following method: the final number is the product of the alphabetic location of the letters in the name, that is, a is equal to 1, z is equal to 26. For example, the Group "usaco" should be 21*19*1*3*15 = 17955. If the remainder 47 of the group is the same as the remainder 47 of huixing, you can tell this group to prepare for departure! (Note that "the remainder of a except B" is the remainder of a after B is divided; 34 is divided by 10 and 4 ).
The program reads the names of huixing and the group and determines whether the two match. If the two match, the output is "go" or the output is "Stay ". The group name and huixing name are a string of upper-case letters without punctuation and spaces, with no more than 6 letters.

Code
# Include <stdio. h>

Main ()
{
Char comet [7], team [7];
Long a = 1, B = 1;
Int I;
File * In = fopen ("ride. In", "R ");
File * out = fopen ("ride. Out", "W ");

Fscanf (in, "% S % s", Comet, team );

For (I = 0; I <strlen (COMET); I ++)
A * = (comet [I]-'A' + 1 );
For (I = 0; I <strlen (Team); I ++)
B * = (Team [I]-'A' + 1 );

If (a % 47) = (B % 47 ))
Fprintf (Out, "Go \ n ");
Else
Fprintf (Out, "stay \ n ");
Fclose (in );
Fclose (out );
Exit (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.