[USACO1.1] Your Ride Is Here Your Ride Is Here

Topic link

Title description
As we all know, there is a UFO behind every comet. These UFOs often come to collect loyal supporters on earth. Unfortunately, their flying saucers can only take one group of supporters on each trip. Therefore, they have to use a clever plan to let these groups know in advance who will be taken away by the comet. They gave a name to each comet and used these names to determine whether the group was taken away by the specific group (who do you think gave these comets the name?). The details on how to match will be told to you below; your task is to write a program that determines whether the group can be taken away by the UFO behind the comet by the group name and the name of the comet.

Both the group name and the 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 team is 21×19×1×3×15=17955. If the group's digital mod47 is equal to the comet's digital mod47, you have to tell the group to be ready to be taken away! (Remember that "a mod b" is the remainder of dividing a by b; 34 mod 10 equals 4)

Write a program, read in the name of the comet and the name of the group, and calculate whether the two names can be matched with the above scheme. If it can be matched, output "GO", otherwise output "STAY". Both the group name and the comet name are a string of capital letters (not more than 6 letters) without spaces or punctuation.

Input format
Line 1: A string of capital letters with a length of 1 to 6, representing the name of the comet.

Line 2: A string of capital letters with a length of 1 to 6, representing the name of the team.

Output format
None

Input and output sample
input #1
COMETQ
HVNGAT
output #1
GO
input #2
ABSTAR
USACO
output #2
STAY
description/hint The
title translation comes from NOCOW.

USACO Training Section 1.1

Code:

//P1200 [USACO1.1]你的飞碟在这儿Your Ride Is He…
#include<iostream>
#include<cstring>
using namespace std;
char s1[10], s2[10];
int main()
{
    
    
	cin >> s1 >> s2;
	long long int n = 1, m = 1, len_1 = strlen(s1), len_2 = strlen(s2);
	for(int i = 0; i < len_1; i++)
		n *= (s1[i] - 64);
	for(int i = 0; i < len_2; i++)
		m *= (s2[i] - 64);
	(n % 47 == m % 47) ? cout << "GO" : cout << "STAY";
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_44826711/article/details/113746556