UVa 1593-alignment of Code

Source: Internet
Author: User

Title Description: Enter a number of lines of code, in accordance with the required format output. Each column of words as far as possible to the left, the word between at least one space.

Idea: Use a string array to find the law.  As long as the boundaries are controlled, the rest is simple. Even the test cases are useless because the UVA Web page is not being brushed. Directly to the code quicksubmit, just worry will time out, but the result is surprising, unexpectedly is AC.      Two more lanes. By the way, I'm embarrassed to use the regular expression.


<p>import Java.util.*;import Java.util.regex.matcher;import java.util.regex.pattern;</p><p> public class Main1593 {</p><p> public static void main (string[] args) {  scanner scan = new SCA Nner (system.in);   pattern p = pattern.compile ("<a target=_blank href=" file://\\s ">\\S</a>+");   string[][] str = new String[1005][1000];  int rows = 0;  int[] rowcnt = new INT[1000];&NB Sp; arrays.fill (rowcnt, 0);   while (Scan.hasnextline ()) {   string line = Scan.nextline ();    matcher m = P.matcher (line);    int cols = 0;   while (M.find ()) {    rowcnt[rows] ++;    str[rows][cols++] = M.group ();    }   rows ++;  }  //system.out.println (rows);   int[] MaxLen = new int[ 850];  arrays.fill (maxlen, 0);   for (int i=0; i<rows;i++) {   for (int j=0; j<rowcnt[i]; J + +) {    maxlen[j] = max (Maxlen[j], str[i][j ].length ());    }  }  for (int i=0; i<rows; i++) {   for (int j=0 ; j<rowcnt[i]; J + +) {    system.out.print (str[i][j]);     if (J < rowcnt[i]-1)      for (int k=0; k<=maxlen[j]-str[i][j].length (); k++)       System.out.print ("");    }   system.out.println ();  } }  public static int Max (int a, int b) {  if (a >= b)    return a;  else  & Nbsp;return b; }}</p>

UVa 1593-alignment of Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.