一个比较困难的问题,高分求答案
//有一具有层次结构的字符串,形如[abc[d[ef]g]h[hi]]..括号表示包含关系.//请将此字符串按照包含还原成内存映象.比如[abc[de]],有一个arra...
//有一具有层次结构的字符串,形如[abc[d[ef]g]h[hi]]..括号表示包含关系.
//请将此字符串按照包含还原成内存映象.比如[abc[de]],有一个arraylist1存放de,然后
//用一个arraylist存放abc,再次将arraylist1作为一个元素存放在arraylist2中.
//前置条件,有一括号匹配的字符串 [abc[d[ef]g]h[hi]]..
//后置条件 返回此字符串的内存映象和打印此内存映象
public ArrayList init(String str);
public String toString();
兄弟们,我已经做出来了。不是那么难的 。我表达不清楚。我重新说下意思。比如ArrayList a = new ArrayList();
a.add("a"); ArrayList b = new ArrayList();
b.add("b");b.add("c");,
a.add(b);
如果打印a,便是字符串[a[bc]]
我的问题是上面问题的可逆步骤,知道字符串[a[bc]],得到ArrayList a 而已 展开
//请将此字符串按照包含还原成内存映象.比如[abc[de]],有一个arraylist1存放de,然后
//用一个arraylist存放abc,再次将arraylist1作为一个元素存放在arraylist2中.
//前置条件,有一括号匹配的字符串 [abc[d[ef]g]h[hi]]..
//后置条件 返回此字符串的内存映象和打印此内存映象
public ArrayList init(String str);
public String toString();
兄弟们,我已经做出来了。不是那么难的 。我表达不清楚。我重新说下意思。比如ArrayList a = new ArrayList();
a.add("a"); ArrayList b = new ArrayList();
b.add("b");b.add("c");,
a.add(b);
如果打印a,便是字符串[a[bc]]
我的问题是上面问题的可逆步骤,知道字符串[a[bc]],得到ArrayList a 而已 展开
22个回答
展开全部
package com.jingmt.middle;
import com.jingmt.database.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class ControlServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
private PreparedStatement pstmt;
private ResultSet rs;
private ArrayList alist;
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
int id=0;
String str_id=request.getParameter("uid");
alist=new ArrayList();
try
{
id=Integer.parseInt(str_id) ;
}
catch(NumberFormatException ex)
{
request.setAttribute("error",str_id);
request.getRequestDispatcher("/jsp/Error.jsp").forward(request,response);
return ;
}
if(!(0<id && id<78))
{
request.setAttribute("error",str_id);
request.getRequestDispatcher("/jsp/OutOfBoundsError.jsp").forward(request,response);
return;
}
String sql="select ProductID,ProductName,UnitPrice from Products where ProductID<? ";
ConnDB db=new ConnDB();
Connection conn=db.getConn();
try
{
pstmt=conn.prepareStatement(sql);
pstmt.setInt(1,id+1);
rs=pstmt.executeQuery();
while(rs.next())
{
ArrayList list=new ArrayList();
for(int i=0;i<3;i++)
{
list.add(rs.getString(i+1));
}
alist.add(list);
}
}
catch(Exception ex)
{
System.out.println(ex.getMessage()+"controlservlet1");
}
// request.setAttribute("list",alist);
// request.getRequestDispatcher("/showservlet").forward(request,response);
HttpSession session=request.getSession();
session.setAttribute("list",alist);
response.sendRedirect("showservlet");
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}
ShowServlet£º
package com.jingmt.client;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class ShowServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
private ArrayList alist;
int noPage;
int n;
int currPage=0;
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
// alist=(ArrayList)request.getAttribute("list");
alist=(ArrayList)request.getSession().getAttribute("list");
if(n!=0)
try{
n=Integer.parseInt(request.getParameter("n"));
}
catch(NumberFormatException ex1)
{
System.out.print(ex1.getMessage()+"here1");
return;
}
else
{
n=0;
}
ArrayList result_alist;
result_alist=this.getItemsFromPage(alist,n);
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>ShowServlet</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
out.print("<form action=showservlet>");
out.println(" <a href=showservlet?n=0>First</a> ");
out.println(" <a href=showservlet?n="+(++currPage)+">Forward</a> ");
out.println(" <a href=showservlet?n="+(--currPage)+">Next</a> ");
out.println(" <a href=showservlet?n="+noPage+">Last</a> "+"<br>");
out.print("</form>");
out.println(" ProductID ");
out.println(" ProductName ");
out.println(" UnitPrice ");
out.println("<br>");
if (result_alist == null) {
result_alist = new ArrayList();
}
for (int i = 0; i < result_alist.size(); i++) {
ArrayList l = (ArrayList) result_alist.get(i);
for (int j = 0; j < l.size(); j++) {
out.println(l.get(j) + " ");
}
out.println("<br>");
}
out.println("</body>");
out.println("</html>");
out.close();
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
public void destroy() {
}
public ArrayList[] divide(ArrayList arraylist) {
noPage = (arraylist.size()-1)/ 10 + 1;
ArrayList[] result = new ArrayList[noPage];
for (int i = 1; i < noPage; i++) {
result[i - 1] = new ArrayList();
for (int j = 0; j < 10; j++) {
result[i - 1].add(arraylist.get((i - 1) *10+ j));
}
}
for (int i = (noPage - 1) *10; i < arraylist.size(); i++) {
result[noPage - 1] = new ArrayList();
result[noPage - 1].add(arraylist.get(i));
}
return result;
}
public ArrayList getItemsFromPage(ArrayList arraylist, int pageNum) {
ArrayList[] result = this.divide(arraylist);
return result[pageNum];
}
import com.jingmt.database.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class ControlServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
private PreparedStatement pstmt;
private ResultSet rs;
private ArrayList alist;
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
int id=0;
String str_id=request.getParameter("uid");
alist=new ArrayList();
try
{
id=Integer.parseInt(str_id) ;
}
catch(NumberFormatException ex)
{
request.setAttribute("error",str_id);
request.getRequestDispatcher("/jsp/Error.jsp").forward(request,response);
return ;
}
if(!(0<id && id<78))
{
request.setAttribute("error",str_id);
request.getRequestDispatcher("/jsp/OutOfBoundsError.jsp").forward(request,response);
return;
}
String sql="select ProductID,ProductName,UnitPrice from Products where ProductID<? ";
ConnDB db=new ConnDB();
Connection conn=db.getConn();
try
{
pstmt=conn.prepareStatement(sql);
pstmt.setInt(1,id+1);
rs=pstmt.executeQuery();
while(rs.next())
{
ArrayList list=new ArrayList();
for(int i=0;i<3;i++)
{
list.add(rs.getString(i+1));
}
alist.add(list);
}
}
catch(Exception ex)
{
System.out.println(ex.getMessage()+"controlservlet1");
}
// request.setAttribute("list",alist);
// request.getRequestDispatcher("/showservlet").forward(request,response);
HttpSession session=request.getSession();
session.setAttribute("list",alist);
response.sendRedirect("showservlet");
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}
ShowServlet£º
package com.jingmt.client;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class ShowServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
private ArrayList alist;
int noPage;
int n;
int currPage=0;
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
// alist=(ArrayList)request.getAttribute("list");
alist=(ArrayList)request.getSession().getAttribute("list");
if(n!=0)
try{
n=Integer.parseInt(request.getParameter("n"));
}
catch(NumberFormatException ex1)
{
System.out.print(ex1.getMessage()+"here1");
return;
}
else
{
n=0;
}
ArrayList result_alist;
result_alist=this.getItemsFromPage(alist,n);
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>ShowServlet</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
out.print("<form action=showservlet>");
out.println(" <a href=showservlet?n=0>First</a> ");
out.println(" <a href=showservlet?n="+(++currPage)+">Forward</a> ");
out.println(" <a href=showservlet?n="+(--currPage)+">Next</a> ");
out.println(" <a href=showservlet?n="+noPage+">Last</a> "+"<br>");
out.print("</form>");
out.println(" ProductID ");
out.println(" ProductName ");
out.println(" UnitPrice ");
out.println("<br>");
if (result_alist == null) {
result_alist = new ArrayList();
}
for (int i = 0; i < result_alist.size(); i++) {
ArrayList l = (ArrayList) result_alist.get(i);
for (int j = 0; j < l.size(); j++) {
out.println(l.get(j) + " ");
}
out.println("<br>");
}
out.println("</body>");
out.println("</html>");
out.close();
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
public void destroy() {
}
public ArrayList[] divide(ArrayList arraylist) {
noPage = (arraylist.size()-1)/ 10 + 1;
ArrayList[] result = new ArrayList[noPage];
for (int i = 1; i < noPage; i++) {
result[i - 1] = new ArrayList();
for (int j = 0; j < 10; j++) {
result[i - 1].add(arraylist.get((i - 1) *10+ j));
}
}
for (int i = (noPage - 1) *10; i < arraylist.size(); i++) {
result[noPage - 1] = new ArrayList();
result[noPage - 1].add(arraylist.get(i));
}
return result;
}
public ArrayList getItemsFromPage(ArrayList arraylist, int pageNum) {
ArrayList[] result = this.divide(arraylist);
return result[pageNum];
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你用堆栈就可以实现这个操作。
你可以参考一下如何实现计算表达式(也就是表达式计算器)
你可以参考一下如何实现计算表达式(也就是表达式计算器)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
应该是个数据结构方面的问题吧? 不过你这个问题太可怕了,你到底想干什么? 还原成内存映像,你是想展示这个表达式在逻辑内存中的相对位置吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
朋友你很专业,但是太专业的问题在百度上面很难找到答案,所以还是建议找老师或者专家请教。。。在这里很难遇到具体的回答的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有没有电脑专业的高手能帮帮我?下面1道题目如何用英文回答?那是1道operating system 的题目.
Discuss situations under which the most frequently used page – replacement algorithm generates fewer page faults than the least recently used page – replacement algorithm. Also discuss under what circumstance the opposite holds.
谁能用英文回答1下这道题?谢谢
Discuss situations under which the most frequently used page – replacement algorithm generates fewer page faults than the least recently used page – replacement algorithm. Also discuss under what circumstance the opposite holds.
谁能用英文回答1下这道题?谢谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询