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

Why PE 希望JAVA的来看一下?

Posted by wskiwwwx at 2010-08-09 22:16:00 on Problem 2271

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// StringBuilder sb = new StringBuilder();
		StringBuilder ans = new StringBuilder();
		int len = 0;
		while (sc.hasNext()) {
			String s = sc.next();

			if (s.equals("<br>")) {
				if (ans.substring(ans.length() - 1, ans.length()).equals(" "))
					ans = new StringBuilder(ans.substring(0, ans.length() - 1));
				ans.append("\n");
				// sb.delete(0, sb.length());
				len = 0;
				continue;
			} else if (s.equals("<hr>")) {
				s = "";
				for (int i = 0; i < 80; ++i)
					s += "-";
				if (ans.length() == 0)
					ans.append(s).append("\n");
				else if (ans.charAt(ans.length() - 1) == '\n')
					ans.append(s).append("\n");
				else
					ans.append("\n").append(s).append("\n");
				len = 0;
				continue;
			} else {
				len += s.length();
				if (len == 80) {
					len = 0;
					ans.append(s).append("\n");
				} else if (len < 80)
					ans.append(s).append(" ");
				else {
					len = s.length();
					ans.delete(ans.length() - 1, ans.length());
					ans.append("\n").append(s).append(" ");
				}
				len++;
			}

		}
		if (ans.substring(ans.length() - 1, ans.length()).equals(" "))
			ans = ans.delete(ans.length() - 1, ans.length());

		System.out.println(ans.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