【USACO1.1.1】Your Ride Is Here

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, can be used to determine if it is a particular 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 should 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" would 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
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 the wrong 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 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".

NOTE 2: Because of the extra characters, be sure to leave enough room for a ‘newline‘ (also notated as ‘\n‘) and an end of string 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:

3 * 15 * 13 * 5 * 20 * 17 = 994500 mod 47 = 27
8 * 22 * 14 * 7 *  1 * 20 = 344960 mod 47 = 27

Because both products evaluate to 27 (when modded by 47), the mission is ‘GO‘.

NOCOW上面有翻译就不班门弄斧了 暑假打算USACO做三四章吧 作为备战ICPC的准备 希望能有很大收获

两串字符串 每个字符对应一个数字 分别对字符串每个字符相应数字相乘对47取模 如果最后结果一样就输出“GO” 否则输出“STAY”

简单模拟 因为是第一道题可能难度偏低

注意USACO提交格式

/*
ID: Alpha Augur
PROG: ride
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
//    ofstream fout ("ride.out");
//    ifstream fin ("ride.in");
    freopen("ride.in", "r", stdin);
    freopen("ride.out", "w", stdout);
    char str1[10], str2[10];
    cin >> str1 >> str2;
    int sum1 = 1, sum2 = 1;
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    for(int i = 0; i < len1; ++i){
        sum1 *= (str1[i] - 'A' + 1);
    }
    for(int i = 0; i < len2; ++i){
        sum2 *= (str2[i] - 'A' + 1);
    }
    if((sum1%47) == (sum2%47)){
        cout << "GO" << endl;
    }
    else{
        cout << "STAY" << endl;
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-02 22:46:44

【USACO1.1.1】Your Ride Is Here的相关文章

【USACO1.2.1】Milking Cows

Milking Cows Three farmers rise at 5 am each morning and head for the barn to milk three cows. The first farmer begins milking his cow at time 300 (measured in seconds after 5 am) and ends at time 1000. The second farmer begins at time 700 and ends a

【USACO1.1.2】Greedy Gift Givers(map)

Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts of money. Each of these friends might or might not give some money to any or all of the other friends. Likewise, each friend might or might not receiv

【USACO1.1.3】Friday the Thirteenth

Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question, write a program that will compute the frequency that the 13t

【USACO1.2.3】Name That Number(字符串处理)

Name That Number Among the large Wisconsin cattle ranchers, it is customary to brand cows with serial numbers to please the Accounting Department. The cow hands don't appreciate the advantage of this filing system, though, and wish to call the member

【USACO 1.1】你的飞碟在这儿

[问题描述] 一个众所周知的事实,在每一慧星后面是一个不明飞行物UFO. 这些不明飞行物时常来收集来自在地球上忠诚的支持者. 不幸地,他们的空间在每次旅行只能带上一群支持者. 他们要做的是用一种聪明的方案让每一个团体人被慧星带走.他们为每个慧星起了一个名字,通过这些名字来决定一个团体是不是特定的慧星带走. 那个相配方案的细节在下面被给出: 你的工作要写一个程序来通过团体的名字和彗星的名字来决定一个组是否应该与在那一颗慧星后面的不明飞行物搭配. 团体的名字和慧星的名字都以下列各项方式转换成一个数字

01月22日【Python3 基础知识】

01月22日[Python3 基础知识] 2.4 计算器 2.5 tuple操作 2.6 dict 2.7 其他常用操作 2.4 计算器 def add(string): total = 0 numbers = [] numbers += string.split("+") for num in numbers: total += int(num.strip()) print("{0} = {1}".format(string, total)) # def redu

Python之路【第十七篇】:Django【进阶篇 】

Python之路[第十七篇]:Django[进阶篇 ] Model 到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞: 创建数据库,设计表结构和字段 使用 MySQLdb 来连接数据库,并编写数据访问层代码 业务逻辑层去调用数据访问层执行数据库操作 import MySQLdb def GetList(sql): db = MySQLdb.connect(user='root', db='wupeiqidb', passwd='1234', host='localhost')

【No.2 Ionic】超级逗表情 App

本人使用Ionic框架开发了一个 超级逗表情 的App 依赖插件 cordova-plugin-app-version 0.1.9 "AppVersion" cordova-plugin-file 4.3.0 "File" cordova-plugin-file-opener2 2.0.2 "File Opener2" cordova-plugin-file-transfer 1.6.0 "File Transfer" cor

【网络流24题】太空飞行计划

[问题描述]W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,…,Em},和进行这些实验需要使用的全部仪器的集合I={ I1, I2,…,In }.实验Ej 需要用到的仪器是I的子集Rj∈I.配置仪器Ik 的费用为ck 美元.实验Ej 的赞助商已同意为该实验结果支付pj 美元.W教授的任务是找出一个有效算法,确定在一次太空飞行中要进行哪些实验并因此而配置哪些仪器才能使太空飞行的净收益最大.这里净收益是指