USACO:Your Ride Is Here
来源:互联网 发布:剑三正太初始脸型数据 编辑:程序博客网 时间:2024/05/17 06:35
USACO,全称USA Computing Olympiad。详情查询http://bk.baidu.com/view/521308.htm
里面的题目很有意思,练习算法不错。昨晚做了道最easy的题目,不到10分钟就搞定了。可能出题的是为
了先给做题的人点自信吧。
点击查看题目
我是用Java写的:
/**//*
* USACO-111
* Product by pandajj at 1:10 2007-12-18 Wuhan
*/
public class YourRideIsHere ...{
public static void main(String[] args) throws Exception ...{
// 输入参数个数不符合要求
if (args.length != 2)
throw new Exception("Usage:java " + "<comet-name> <group-name>");
char[] comet = args[0].toUpperCase().toCharArray();
char[] group = args[1].toUpperCase().toCharArray();
// 输入字符串长度大于6
if (comet.length > 6 || group.length > 6)
throw new Exception(
"The name's length of coment or group must betwee 1 and 6!");
int cometSum = product(comet);
int groupSum = product(group);
if (cometSum % 47 == groupSum % 47)
System.out.println("Go");
else
System.out.println("STAY");
}
// 计算char数组中的字母所代表值的乘积
private static int product(char[] chars) ...{
int multiplier = 1;
for (char ch : chars)
multiplier *= ((int) ch - 64); // 'A'的ASCII码为65
return multiplier;
}
}
* USACO-111
* Product by pandajj at 1:10 2007-12-18 Wuhan
*/
public class YourRideIsHere ...{
public static void main(String[] args) throws Exception ...{
// 输入参数个数不符合要求
if (args.length != 2)
throw new Exception("Usage:java " + "<comet-name> <group-name>");
char[] comet = args[0].toUpperCase().toCharArray();
char[] group = args[1].toUpperCase().toCharArray();
// 输入字符串长度大于6
if (comet.length > 6 || group.length > 6)
throw new Exception(
"The name's length of coment or group must betwee 1 and 6!");
int cometSum = product(comet);
int groupSum = product(group);
if (cometSum % 47 == groupSum % 47)
System.out.println("Go");
else
System.out.println("STAY");
}
// 计算char数组中的字母所代表值的乘积
private static int product(char[] chars) ...{
int multiplier = 1;
for (char ch : chars)
multiplier *= ((int) ch - 64); // 'A'的ASCII码为65
return multiplier;
}
}
由于时间有限,没有时间想更好的算法。所以希望有更好算法的牛人能与我交流。。小弟算法菜的很。
今后有时间还会继续做该题库里面的题目,后面的题目越来越难,还望与有兴趣者交流。
本人qq:396738007
本人博客:hi.baidu.com/homefovever
- USACO:Your Ride Is Here
- your ride is here(USACO)
- usaco--Your Ride Is Here
- [USACO] Your Ride Is Here
- USACO:Your Ride Is Here
- USACO Your Ride Is Here
- USACO:Your Ride is here
- 【USACO】Your Ride Is Here
- usaco Your Ride Is Here
- USACO Your Ride Is Here
- USACO Your Ride Is Here
- USACO | Your Ride Is Here
- USACO->Your Ride Is Here
- USACO 1.1 Your Ride Is Here (ride)
- My USACO Analysis:Your Ride Is Here
- USACO 1.1.1 Your Ride Is Here
- USACO:Section 1.1 Your Ride Is Here
- USACO 1.1-Your ride is here
- SuperSearch(超级网搜)
- 13.13 sqlite3 -- DB-API 2.0 SQLite数据库接口[Python参考库翻译]
- 使用“PC定时执行专家”,提高你的工作效率
- 电脑当闹钟
- 正式开始技术生涯
- USACO:Your Ride Is Here
- 资深专家给.NET初学者的学习建议
- java事务处理
- 静悄悄的革命
- 通过一组直观的数据了解单链表和线性表的特点
- UBB(c#完整版)
- 收集一些.NET开发资源站点和部分优秀.NET开源项目
- Borland 简介
- A Error in C++ primer English Fourth edition