第一题
题目描述有点迷,反复调试都是0,一看AC竟然是三步问题??!
原提交代码(通过0):
public static int CalulateMethodCount (int num_money) { int dp[] = new int[num_money+1]; if(num_money<=0) return 0; dp[0]=0; dp[1]=1; for (int i = 1; i <num_money; i++) { int k = 0,count=0; while(count<=i){ k+=dp[count]; count++; } dp[i+1]=k+1; } return dp[num_money]; //甚至可以直接一行: //return 1<<(num_money-1); }第二题
啊,用例考虑有问题,这是我提交的,只有0.4┭┮﹏┭┮
import java.util.Scanner; import java.util.Stack; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s = scanner.nextLine(); s=s.replaceAll("\\t"," "); //s=s.replaceAll("\\s{1,}"," "); String [] strings = s.split(" "); Stack<String> stack = new Stack<>(); Stack<String> undo = new Stack<>(); for(String string :strings){ if(string.equals("undo") && !stack.empty()){ undo.push(stack.pop()); } else if (string.equals("redo") && !undo.empty()) { stack.push(undo.pop()); } else{ stack.push(string); } } Stack<String> res = new Stack<>(); while(!stack.empty()){ res.push(stack.pop()); } StringBuffer sb = new StringBuffer(); while (!res.empty()){ sb.append(res.pop()+" "); } String resString = sb.toString(); System.out.println(resString.trim()); } }
全部评论
(3) 回帖