纪念USACO的第一次

        这实在是没什么好写的,这两天才刚接触USACO,真的是非常不错的一个平台,只是这个平台太可爱了,一上来就有好几个section要完成,题目也都不难,只是,它的规则好让人蛋疼,整了好久才过了那第一个程序。为了一道让我纠结这么久的水题,我决定把代码贴上来作纪念!

Your Ride Is Here

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:

InputOutput
COMETQ
HVNGAT
GO
ABSTAR
USACO 
STAY

PROGRAM NAME: ride

This means that you fill in your header with:
PROG: ride

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".

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

/*
ID: ch.shiq1
LANG: C++
TASK: ride
*/
#include<iostream>
#include<string>
#include<fstream>
using namespace std;

int converted(string str)
{
	int con = 1;

	char* buf = new char[str.length()];
	str.copy(buf, str.length());
	for(int i = 0; i <= str.length(); i++)
	{
		buf[i] = toupper(buf[i]);
		con *= (int)buf[i] - 64;
	}
	con = con % 47;
	return con;
}
int main()
{
    ofstream fout ("ride.out");
    ifstream fin ("ride.in");
	string comet;
	string group;

	fin >> comet;
	fin >> group;

	if(converted(comet) == converted(group))
	fout << "GO" << endl;
	else
	fout << "STAY" << endl;
	
	return 0;
}

总结一下在这个平台上有几点要注意的(C++)

1、程序最上端要有三个注释,分别是你的ID,语言和题目的名称

2、记得包含头文件fstream,因为程序中的输入输出都是要用文件格式的。为了这点我悲催了好久。

3、既然用文件格式,那么fout和fin两个文件自然必不可少啦,文件名分别用题目的名称加.out和.in

4、记得加上return让程序结束


其他的不多说了,题目更加是没什么好说的,以后好好玩!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值