博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Topcoder tournaments Inv 2001R1
阅读量:6357 次
发布时间:2019-06-23

本文共 5144 字,大约阅读时间需要 17 分钟。

250:
public class HowEasy {	public static void main(String[] args) {		HowEasy m = new HowEasy();		System.out.println(m.pointVal("This is a problem statement"));		System.out.println(m.pointVal("523hi."));		System.out.println(m.pointVal("Implement a class H5 which contains some method."));		System.out.println(m.pointVal(" no9 . wor7ds he8re. hj.."));	}	public int pointVal(String str) {		int s=0,e=0;		int wordNum=0,charNum=0;		int len = str.length();		str = str.trim();		String[] strs = str.split(" ");		for (String string : strs) {			if(string.matches("[a-zA-Z]+\\.?")) {				charNum++;				wordNum+=string.length();				if(string.endsWith(".")) {					wordNum--;				}			}			//System.out.println(string+"  charNum:"+charNum+"  wordNum:"+wordNum);		}		if(0==wordNum) {			return 250;		}		int judge = wordNum / charNum;		if(judge<=3) {			return 250;		} else if(4==judge||5==judge) {			return 500;		} else {			return 1000;		}	}}

  

1000:

Problem Statement

    
***Note:  Please keep programs under 7000 characters in length.  Thank youClass Name: PrerequisitesMathod Name: orderClassesParameters: String[]Returns: String[]You are a student at a college with the most unbelievably complex prerequisitestructure ever. To help you schedule your classes, you decided to put togethera program that returns the order in which the classes should be taken.  Implement a class Prerequisites which contains a method orderClasses.  Themethod takes a String[] that contains the classes you must take and returns aString[] of classes in the order the classes should be taken so that allprerequisites are met.String[] elements will be of the form (and TopCoder will ensure this):"CLASS: PRE1 PRE2 ..." where PRE1 and PRE2 are prerequisites of CLASS.  CLASS,PRE1, PRE2, ... consist of a department name (3 or 4 capital letters, A-Zinclusive) followed by a class number (an integer between 100 and 999,inclusive).  The department name should be immediately followed by the classnumber with no additional characters, numbers or spaces (i.e. MATH217).  It isnot necessary for a class to have prerequisites.  In such a case, the colon isthe last character in the String.  You can only take one class at a time, therefore, use the following rules todetermine which class to take :1) Any prerequisite class(es) listed for a class must be taken before the classcan be taken.2) If multiple classes can be taken at the same time, you take the one with thelowest number first, regardless of department.3) If multiple classes with the same number can be taken at the same time, youtake the department name which comes first in alphabetical order.  4) If the inputted course schedule has errors, return a String[] of length 0.There is an error if it is impossible to return the classes in an order suchthat all prerequisites are met, or if a prerequisite is a course that does nothave its own entry in the inputted String[].Examples of valid input Strings are:"CSE111: CSE110 MATH101""CSE110:"Examples of invalid input Strings are:"CS117:" (department name must consist of 3 - 4 capital letters, inclusive)"cs117:" (department name must consist of 3 - 4 capital letters, inclusive)"CS9E11:" (department name must be letters only)"CSE110: " (no trailing spaces allowed)"CSE110: CSE101 " (no trailing spaces allowed)"MATH211: MAM2222" (class number to large)"MATH211: MAM22" (class number to small)"ENGIN517: MATH211" (department name to large)Here is the method signature (be sure your method is public):String[] orderClasses(String[] classSchedule);TopCoder will make sure classSchedule contains between 1 and 20 Strings,inclusive, all of the form above.  The Strings will have between 1 and 50characters, inclusive.  TopCoder will check that the syntax of the Strings arecorrect: The Strings will contain a valid class name, followed by a colon,possibly followed by a series of unique prerequisite classes separated bysingle spaces.  Also, TopCoder will ensure that each class has at most oneentry in the String[]. Examples:If classSchedule={"CSE121: CSE110","CSE110:","MATH122:",}The method should return: {"CSE110","CSE121","MATH122"}If classSchedule={"ENGL111: ENGL110","ENGL110: ENGL111"}The method should return: {}If classSchedule=["ENGL111: ENGL110"}The method should return: {}If classSchedule={"CSE258: CSE244 CSE243 INTR100""CSE221: CSE254 INTR100""CSE254: CSE111 MATH210 INTR100""CSE244: CSE243 MATH210 INTR100""MATH210: INTR100""CSE101: INTR100""CSE111: INTR100""ECE201: CSE111 INTR100""ECE111: INTR100""CSE243: CSE254""INTR100:"}The method should return:{"INTR100","CSE101","CSE111","ECE111","ECE201","MATH210","CSE254","CSE221","CSE243","CSE244","CSE258"}

Definition

    
Class: Prerequisites
Method: orderClasses
Parameters: String[]
Returns: String[]
Method signature: String[] orderClasses(String[] param0)
(be sure your method is public)
    
 

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.     

转载于:https://www.cnblogs.com/TLightSky/archive/2012/03/16/2400831.html

你可能感兴趣的文章
使用 MPI for Python 并行化遗传算法
查看>>
widget
查看>>
paramiko安装及使用
查看>>
Java私塾:研磨设计模式 之 访问者模式(Visitor)
查看>>
我的友情链接
查看>>
《Python网络数据采集》读书笔记(六)
查看>>
Linux必学的60个命令
查看>>
iptables 学习笔记 (上)
查看>>
Windows Server 2012 R2 Active Directory(活动目录)实验一
查看>>
android viewpager 无限左右滑动
查看>>
linux下SSH远程连接服务慢解决方案
查看>>
利用mic visual studio 2010 编译器执行wincap获取网络适配器的代码
查看>>
HTML
查看>>
CENTOS7下编译安装PHP-5.4以及配置phpMyAdmin
查看>>
磁盘显示无法访问拒绝访问,里面的资料怎样找到
查看>>
Java之品优购课程讲义_day07(5)
查看>>
Java的新项目学成在线笔记-day3(八)
查看>>
路由简单的实验
查看>>
好程序员web前端教程分享js reduce方法使用教程
查看>>
零基础学习大数据Hadoop需要什么准备?Hadoop如何发展起来的?
查看>>