Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

如何才能正确提交

Posted by xnxylxh at 2011-05-12 10:48:11 on Problem 3650
各位大侠,小弟第一次来做这里做题目,不知道我这样做是否正确,ID3650这个题,我在自己机器上跑没问题了,一提交上服务器就报不少错误,比如:Main.java:9: class PercentSolution is public, should be declared in a file named PercentSolution.java
public class PercentSolution {
       ^
1 error
(我觉得奇怪,我只是传源码,文件又不要我建立,为什么出现这种错误)



我的源码如下:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class PercentSolution {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));//接收控制台输入
		StringBuilder sb = new StringBuilder();
		int temp, num = 0;
		List<String> list = new ArrayList<String>();
		try {
			while ((temp = br.read()) != -1) {
				sb.append((char) temp);
				if (temp == '#') {//字符#作为输入结束标志
					break;
				}
			}
			for (int j = 0; j < sb.length(); j++) {
				if (((int) sb.toString().charAt(0)) == 32
						|| ((int) sb.toString().charAt(sb.length() - 2)) == 32) {//首字符和最末一个字符不能为空格
					num = 2;
					break;
				}
				if (sb.toString().charAt(j) != '#') {
					list.add(j, String.valueOf(sb.toString().charAt(j)));//将字符作为String存入list中,这样做方便下面处理
				}
				if (j <= sb.length() - 3) {
					if ((int) sb.toString().charAt(j) == 32
							&& (int) sb.toString().charAt(j + 1) == 32) {//不能有连续两个空格
						num = 1;
						break;
					}
				}
			}
			sb.delete(0, sb.length());
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

		if (num == 0) {//通过上面的判断,符合题目条件,进行处理
			for (int i = 0; i < list.size(); i++) {
				if (list.get(i).equals(" ")) {//开始处理,如果输入中有空格字符,则替换为“20%”,以下类推
					list.set(i, "%20");
				} else if (list.get(i).equals("!")) {
					list.set(i, "%21");
				} else if (list.get(i).equals("$")) {
					list.set(i, "%24");
				} else if (list.get(i).equals("%")) {
					list.set(i, "%25");
				} else if (list.get(i).equals("(")) {
					list.set(i, "%28");
				} else if (list.get(i).equals(")")) {
					list.set(i, "%29");
				} else if (list.get(i).equals("*")) {
					list.set(i, "%2a");
				}
			}
			for (int j = 0; j < list.size(); j++) {
				sb.append(list.get(j));//将处理过的list中的内容,复制加到sb中,为了符合题目的输出要求
			}
		}
		if (sb.toString().length() > 0)
			System.out.println(sb.toString());
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator