Package cn.edu.zju.acm.onlinejudge.bean

Examples of cn.edu.zju.acm.onlinejudge.bean.Problem


                ps.setLong(3, contestId);
                ResultSet rs = ps.executeQuery();
                while (rs.next()) {
                  Long probemid=new Long(rs.getLong("problem_id"));
                  if(!solvedid.contains(probemid)) {
                      Problem p = new Problem();
                      p.setContestId(contestId);
                      p.setId(rs.getLong("problem_id"));
                      p.setCode(rs.getString("code"));
                      p.setTitle(rs.getString("title"));
                      solved.add(p);
                      solvedid.add(probemid);
                  }
                    String comment=rs.getString("judge_comment");
                  if(!confirmed.contains(probemid) && "Yes".equals(comment)) {
                      Problem p = new Problem();
                      p.setContestId(contestId);
                      p.setId(rs.getLong("problem_id"));
                      p.setCode(rs.getString("code"));
                      p.setTitle(rs.getString("title"));
                      confirmed.add(p);
                      confirmedid.add(probemid);
                  }
                }
            } finally {
View Full Code Here



        // user can always view their own submission
        UserProfile user = context.getUserProfile();
        if (user == null || user.getId() != submission.getUserProfileId()) {
            Problem problem = ContestManager.getInstance().getProblem(submission.getProblemId());
            context.setAttribute("problem", problem);
            ActionForward forward = this.checkProblemViewSourecPermission(mapping, context, null);
            if (forward != null) {
                response.sendError(404);
                return null;
View Full Code Here

                if (line.trim().length() == 0) {
                    continue;
                }
                // CSV format code,title,checker,tl,ml,ol,sl,author,source,contest
                String[] values = ProblemManager.split(line);
                Problem problem = new Problem();
                if (values.length < 2) {
                    messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidline"));
                    continue;
                }
                if (values[0].length() > 8 || values[0].length() == 0) {
                    messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidcode"));
                }

                problem.setCode(values[0]);

                if (values[1].length() > 128 || values[1].length() == 0) {
                    messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidtitle"));
                }
                problem.setTitle(values[1]);

                if (values.length > 2 && Boolean.valueOf(values[2]).booleanValue()) {
                    problem.setChecker(true);
                }

                Limit limit = new Limit();

                Integer tl = ProblemManager.retrieveInt(values, 3);
                if (tl != null) {
                    if (tl.intValue() < 0) {
                        messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidtl"));
                    } else {
                        limit.setTimeLimit(tl.intValue());
                    }
                }
                Integer ml = ProblemManager.retrieveInt(values, 4);
                if (ml != null) {
                    if (ml.intValue() < 0) {
                        messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidml"));
                    } else {
                        limit.setMemoryLimit(ml.intValue());
                    }
                }
                Integer ol = ProblemManager.retrieveInt(values, 5);
                if (ol != null) {
                    if (ol.intValue() < 0) {
                        messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidol"));
                    } else {
                        limit.setOutputLimit(ol.intValue());
                    }
                }
                Integer sl = ProblemManager.retrieveInt(values, 6);
                if (sl != null) {
                    if (sl.intValue() < 0) {
                        messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidsl"));
                    } else {
                        limit.setSubmissionLimit(sl.intValue());
                    }
                }
                if (tl != null || ml != null || ol != null || sl != null) {
                    if (tl != null && ml != null && ol != null && sl != null) {
                        problem.setLimit(limit);
                    } else {
                        messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.missinglimit"));
                    }
                }

                if (values.length > 7 && values[7].length() > 0) {
                    if (values[7].length() > 32) {
                        messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidauthor"));
                    } else {
                        problem.setAuthor(values[7]);
                    }
                }

                if (values.length > 8 && values[8].length() > 0) {
                    if (values[8].length() > 128) {
                        messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidsource"));
                    } else {
                        problem.setSource(values[8]);
                    }
                }

                if (values.length > 9 && values[9].length() > 0) {
                    if (values[9].length() > 128) {
                        messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.invalidcontest"));
                    } else {
                        problem.setContest(values[9]);
                    }
                }
                ProblemEntry entry = new ProblemEntry();
                entry.setProblem(problem);
                if (entryMap.containsKey(problem.getCode())) {
                    messages.add(messageKey, new ActionMessage("onlinejudge.importProblem.reduplicatecode"));
                }
                entryMap.put(problem.getCode(), entry);
            }
        } catch (IOException e) {
            messages.add("error", new ActionMessage("onlinejudge.importProblem.invalidproblemscsv"));
        }
        if (messages.size() > 0) {
View Full Code Here

        row.createCell((short) 1).setCellValue("Handle");
        row.createCell((short) 2).setCellValue("Nickname");
        row.createCell((short) 3).setCellValue("Solved");
        short columnIndex = 4;
        for (Problem problem2 : problems) {
            Problem problem = problem2;
            row.createCell(columnIndex).setCellValue(problem.getCode());
            columnIndex++;
        }
        row.createCell(columnIndex).setCellValue("Penalty");

        int rowIndex = 6;
View Full Code Here

        writer.write(lineHolder);
        writer.write(lineHolder);

        writer.write("Rank\tHandle\tNickname\tSolved\t");
        for (Problem problem2 : problems) {
            Problem problem = problem2;
            writer.write(problem.getCode());
            writer.write("\t");
        }
        writer.write("Penalty");
        writer.write(lineHolder);
View Full Code Here

        ActionForward forward = this.checkProblemAdminPermission(mapping, context, isProblemset);
        if (forward != null) {
            return forward;
        }

        Problem problem = context.getProblem();
        ActionMessages messages = new ActionMessages();
        ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
        problemPersistence.deleteProblem(problem.getId(), context.getUserProfile().getId());

        messages.add("message", new ActionMessage("onlinejudge.deleteProblem.success"));

        this.saveErrors(context.getRequest(), messages);
        String back = isProblemset ? "showProblems" : "showContestProblems";
View Full Code Here

    public static void init() throws Exception {
        ReflectionUtil.setFieldValue(DAOFactory.class, "languageDAO", new MockLanguageDAO());
        ReflectionUtil.setFieldValue(DAOFactory.class, "problemDAO", new MockProblemDAO());
        ReflectionUtil.setFieldValue(DAOFactory.class, "submissionDAO", new MockSubmissionDAO());
        ReflectionUtil.setFieldValue(DAOFactory.class, "referenceDAO", new MockReferenceDAO());
        Problem problem = new Problem();
        problem.setId(0);
        problem.setRevision(0);
        Limit limit = new Limit();
        limit.setTimeLimit(1);
        limit.setMemoryLimit(1024);
        limit.setOutputLimit(1);
        problem.setLimit(limit);
        Reference reference = new Reference();
        reference.setReferenceType(ReferenceType.INPUT);
        reference.setContent("0 0\n1 2\n2 3\n".getBytes("ASCII"));
        DAOFactory.getReferenceDAO().save(reference, 0);
        DAOFactory.getReferenceDAO().save(reference, 1);
View Full Code Here

    public static void init() throws Exception {
  ReflectionUtil.setFieldValue(DAOFactory.class, "languageDAO", new MockLanguageDAO());
  ReflectionUtil.setFieldValue(DAOFactory.class, "problemDAO", new MockProblemDAO());
  ReflectionUtil.setFieldValue(DAOFactory.class, "submissionDAO", new MockSubmissionDAO());
  ReflectionUtil.setFieldValue(DAOFactory.class, "referenceDAO", new MockReferenceDAO());
  Problem problem = new Problem();
  problem.setId(0);
  problem.setRevision(0);
  Limit limit = new Limit();
  limit.setTimeLimit(1);
  limit.setMemoryLimit(1024);
  limit.setOutputLimit(1);
  problem.setLimit(limit);
  Reference reference = new Reference();
  reference.setReferenceType(ReferenceType.INPUT);
  reference.setContent("0 0\n1 2\n2 3\n".getBytes("ASCII"));
  DAOFactory.getReferenceDAO().save(reference, 0);
  DAOFactory.getReferenceDAO().save(reference, 1);
View Full Code Here

    public void update(Problem problem) {
        problemMap.put(problem.getId(), cloneProblem(problem));
    }

    private Problem cloneProblem(Problem problem) {
        Problem ret = new Problem();
        ret.setId(problem.getId());
        ret.setRevision(problem.getRevision());
        ret.setLimit(cloneLimit(problem.getLimit()));
        ret.setChecker(problem.isChecker());
        return ret;
    }
View Full Code Here

                StatisticsManager.getInstance().getContestStatistics(contest.getId(),
                                                                     (int) ((pageNumber - 1) * problemsPerPage),
                                                                     (int) problemsPerPage);
        for(int i=0;i<problems.size();++i)
        {
            Problem p = (Problem)problems.get(i);
            int ac = contestStatistics.getCount(i, 0);
            int total = contestStatistics.getProblemCount(i);
            p.setTotal(total);
            p.setAC(ac);
            if(total==0)
            {
                p.setRatio(0);
            }
            else
            {
                p.setRatio((double)ac/(double)total);
            }
        }
        String order=context.getRequest().getParameter("order");
        if(order!=null)
        {
            if(order.equalsIgnoreCase("ratio"))
            {
        Collections.sort(problems, new Comparator() {
          public int compare(Object o1, Object o2) {
            return (((Problem)o2).getRatio() - ((Problem)o1).getRatio())>0? 1 : -1;
          }}
          );
      } else if(order.equalsIgnoreCase("ac"))
            {
        Collections.sort(problems, new Comparator() {
          public int compare(Object o1, Object o2) {
            return ((Problem)o2).getAC() - ((Problem)o1).getAC();
          }}
          );
      } else if(order.equalsIgnoreCase("all"))
            {
        Collections.sort(problems, new Comparator() {
          public int compare(Object o1, Object o2) {
            return ((Problem)o2).getTotal() - ((Problem)o1).getTotal();
          }}
          );
      }
    }
     
        UserStatistics userStatistics = null;
        if (context.getUserProfile() != null && problems.size() > 0) {
            userStatistics =
                    StatisticsManager.getInstance()
                                     .getUserStatistics(contest.getId(), context.getUserProfile().getId());
        }

        context.setAttribute("problems", problems);
        context.setAttribute("pageNumber", (new Long(pageNumber)).toString());
        context.setAttribute("ContestStatistics", contestStatistics);
        context.setAttribute("UserStatistics", userStatistics);
        context.setAttribute("totalPages", new Long(totalPages));
        context.setAttribute("currentPage", new Long(pageNumber));
        if (this.checkContestAdminPermission(mapping, context, isProblemset, true) == null &&
            "true".equalsIgnoreCase(context.getRequest().getParameter("check"))) {
            List<String> checkMessages = new ArrayList<String>();
            for (Object obj : problems) {
                Problem p = (Problem) obj;
                this.checkExists("Text", this.getReferenceLength(p, ReferenceType.DESCRIPTION), "ERROR", checkMessages,
                                 p);
                this.checkExists("Input", this.getReferenceLength(p, ReferenceType.INPUT), "ERROR", checkMessages, p);
                if (p.isChecker()) {
                    this.checkExists("Output", this.getReferenceLength(p, ReferenceType.OUTPUT), "WARNING",
                                     checkMessages, p);
                    // checkExists("Checker", getReferenceLength(p, ReferenceType.CHECKER), "WARNING", checkMessages,
                    // p);
                    this.checkExists("Checker source", this.getReferenceLength(p, ReferenceType.CHECKER_SOURCE),
View Full Code Here

TOP

Related Classes of cn.edu.zju.acm.onlinejudge.bean.Problem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.