Your UFO here Your Ride Is Here

Copyright: blogger original, welcome to reprint. Please indicate the source https://blog.csdn.net/baidu_41248654/article/details/78942002

Your Ride Is Here

Link: USACO , Luo Valley P1200

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
HVNGAT
GO
ABSTAR
USACO 
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:
15 * 3 * 13 * 5 * 20 * 17 = 994 500 27 v 47 = 
8 * 22 * 14 * 7 * 1 * 20 = 344 960 = 27 to 47

Because both products evaluate to 27 (when modded by 47), themission is 'GO'. 

A simple string title, began the journey as USACO

/*
ID: Kingrrr
TASK: ride
LANG: C++
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char str1[8],str2[8];
int num1[8],num2[8],tot1=1,tot2=1;
int main()
{
	freopen("ride.in","r",stdin);
	freopen("ride.out","w",stdout);
	scanf("%s",str1);
	scanf("%s",str2);
	int len1=strlen(str1);
	int len2=strlen(str2);
	for(int i=0; i<len1; i++)
		num1[i]=str1[i]-'A'+1;
	for(int i=0; i<len2; i++)
		num2[i]=str2[i]-'A'+1;
	for(int i=0; i<len1; i++)
		tot1*=num1[i];
	for(int i=0; i<len2; i++)
		tot2*=num2[i];
	if(tot1%47==tot2%47)
		printf("GO\n");
	else
		printf("STAY\n");
	return 0;
}

USACO revision, and this question moved from Section1.1 Section1.2

Luo Gu translation (from NOCOW):

Title Description

As we all know, after each comet has a UFO. These UFO often come to collect loyal supporters on earth. Unfortunately, their flying saucer each trip can only bring a group of supporters. Therefore, they use a clever scheme to let these groups know ahead of time who was taken away by a comet. They played a name for each comet to determine that particular group this group is not being taken away by these names (Who do you think these comets to take the name of it?). Details on how the match will tell you the following; Your task is to write a program to determine whether this group could be behind the comet UFO taken by the group name and the name of the comet.

Circle name and the name of the comet are converted into a digital in the following manner: the final number is in the name of all the letters of the plot, where "A" is 1, "Z" is 26. For example, "USACO" group is 21 * 19 * 15 * 1 * 3 = 17955. If the number is equal to the group's mod 47 digital comet mod 47, you have to tell the team needed to get ready! (Remember that "a mod b" is the remainder of a divided by b; 34 mod 10 is equal to 4)

Write a program that reads comet names and group names and is calculated using the above two program names will be with them, if they can match, it outputs "GO", otherwise output "STAY". Circle name and the name of the comet are no spaces or punctuation string of capital letters (no more than six letters).

Input and output formats

Input formats:

Line 1: a length of string to upper case 1 to 6, represents the name of the comet.

Line 2: the length of a string to upper case 1 to 6, represents the name of the team.



Guess you like

Origin blog.csdn.net/baidu_41248654/article/details/78942002