Created
October 10, 2013 03:51
-
-
Save wfwei/6912786 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.util.Stack; | |
public class MaxArea { | |
public static int maxArea(int[] heights) { | |
int max = Integer.MIN_VALUE; | |
Stack<Integer> inc = new Stack<Integer>(); | |
for (int i = 0; i < heights.length; i++) { | |
while (!inc.isEmpty() && heights[inc.peek()] > heights[i]) { | |
int curIdx = inc.pop(); | |
if(!inc.isEmpty()) | |
max = Math.max((curIdx - inc.peek())*heights[curIdx], max); | |
else | |
max = Math.max((1 + curIdx) * heights[curIdx], max); | |
} | |
inc.push(i); | |
} | |
return max; | |
} | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
Scanner inputScanner = new Scanner(System.in); | |
int N = inputScanner.nextInt(); | |
int[] heights = new int[N+1]; | |
for(int i=0; i<N; i++){ | |
heights[i] = inputScanner.nextInt(); | |
} | |
System.out.println(maxArea(heights)); | |
inputScanner.close(); | |
} | |
} | |
import java.util.HashMap; | |
import java.util.Scanner; | |
public class Main { | |
static HashMap<String, String> table = new HashMap<String, String>(); | |
static { | |
table.put("38", "&"); | |
table.put("amp", "&"); | |
table.put("60", "<"); | |
table.put("lt", "<"); | |
table.put("62", ">"); | |
table.put("gt", ">"); | |
table.put("160", " "); | |
table.put("nbsp", " "); | |
table.put("165", "¥"); | |
} | |
public static String translate(String input) { | |
StringBuffer result = new StringBuffer(); | |
while (input.length() > 0) { | |
int end = 0; | |
if (input.startsWith("&#")) { | |
end = input.indexOf(';'); | |
// TODO how to convert a number to unicode | |
result.append(table.get(input.substring(2, end))); | |
} else if (input.startsWith("&")) { | |
end = input.indexOf(';'); | |
result.append(table.get(input.substring(1, end))); | |
} else { | |
result.append(input.charAt(0)); | |
} | |
input = input.substring(end + 1); | |
} | |
return result.toString(); | |
} | |
public static void main(String[] args) { | |
Scanner inputScanner = new Scanner(System.in); | |
while (inputScanner.hasNextLine()) { | |
String input = inputScanner.nextLine(); | |
System.out.println(translate(input)); | |
} | |
inputScanner.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment