3

我正在 Android 上开发一个简单的测验应用程序。随着测验的推进,测验中的问题应该变得更加困难。现在,我正在尝试实现一个静态方法,该方法采用Question对象列表并根据难度生成(选择)适当问题的子列表,并且应该对其进行排序(列表中的第一个问题是最简单的问题)。该应用程序有 3 个难度级别(模式)。

这是方法片段:

public static List<Question> getQuestions(List<Question> availableQuestions,
                                       int quizDifficulty, int numberOfQuestion)
{
    if(availableQuestions.size() < numberOfQuestion)
        throw NotEnoughQuestionsException();

    List<Question> questions = new ArrayList<Question>(numberOfQuestion);
    if(quizDifficulty == 0) // Easy
    {
        // ...
        return questions;
    }
    else if(quizDifficulty == 2) // Hard
    {
        // ...
        return questions;   
    }
    else /*if(quizDifficulty == 1)*/ // Normal
    {
        // ...
        return questions;
    }
}

每个Question对象都有一个在 to 范围内的字段,difficulty该字段可以通过方法访问。1 (most simple)10 (most difficult)getDifficulty()

考虑到方法的实现,我决定将题型的难度设置为不超过8模式的级别,在模式中Easy应该超过级别3,在模式中Hard的级别9和级别之间。2Normal

问题是提供的问题列表availableQuestions不能保证包含所有要求的难度级别,例如,所有问题都在级别 1。

所以,我的问题是,实现这种方法的最佳想法是什么?


编辑:

这是我到目前为止的进展:

public static List<Question> getQuestions(List<Question> availableQuestions,
                                      int quizDifficulty, int numberOfQuestion)
{
    if(availableQuestions.size() < numberOfQuestion)
        throw NotEnoughQuestionsException();

    List<Question> questions = new ArrayList<Question>(numberOfQuestion);
    Map<Integer, List<Question>> map = new HashMap<Integer, List<Question>>();
    for(int i = 1; i <= 10; i++) map.put(i, new ArrayList<Question>());
    for(Question question : availableQuestions) 
        map.get(question.getDifficulty()).add(question);

    int L1 = map.get(1).size(); // number of questions with level 1
    int L2 = map.get(2).size();
    int L3 = map.get(3).size();
    int L4 = map.get(4).size();
    int L5 = map.get(5).size();
    int L6 = map.get(6).size();
    int L7 = map.get(7).size();
    int L8 = map.get(8).size();
    int L9 = map.get(9).size();
    int L10 = map.get(10).size();

    final int L1_TO_L8  = 0;
    final int L1_TO_L9  = 1;
    final int L1_TO_L10 = 2;
    final int L2_TO_L9  = 3;
    final int L2_TO_L10 = 4;
    final int L3_TO_L10 = 5;

    int status;

    if(difficulty == 0) // Easy (level 1 to level 8)
    {
        int missing = questionsCount - (L1+L2+L3+L4+L5+L6+L7+L8);
        if(missing > 0) // not enough questions in L1 through L8
        {
            if(missing - L9 > 0) // we must include all the level
            {
                status = L1_TO_L10;
            }
            else // enough questions in L1 through L9
            {
                status = L1_TO_L9;
            }
        }
        else // enough questions in L1 through L8
        {
            status = L1_TO_L8;
        }
    }
    else if(difficulty == 2) // Hard (level 3 to level 10)
    {
        int missing = questionsCount - (L3+L4+L5+L6+L7+L8+L9+L10);
        if(missing > 0) // not enough questions in L3 through L10
        {
            if(missing - L2 > 0) // we must include all the level
            {
                status = L1_TO_L10;
            }
            else // enough questions in L2 through L10
            {
                status = L2_TO_L10;
            }
        }
        else // enough questions in L3 through L10
        {
            status = L3_TO_L10;
        }
    }
    else /*if(difficulty == 1)*/ // Normal (level 2 to level 9)
    {
        int missing = questionsCount - (L2+L3+L4+L5+L6+L7+L8+L9);
        if(missing > 0) // not enough questions in L2 through L9
        {
            if(missing - L1 > 0) // we must include all the level
            {
                status = L1_TO_L10;
            }
            else // enough questions in L1 through L9
            {
                status = L1_TO_L9;
            }
        }
        else // enough questions in L2 through L9
        {
            status = L2_TO_L9;
        }
    }

    // ...
}
4

5 回答 5

2

最简单的解决方案是根据您的模式获取具有一定级别的所有问题,然后您可以对此列表进行排序,例如:

public static List<Question> getQuestions(List<Question> availableQuestions, 
     int quizDifficulty, int numberOfQuestion)
  {
      if(availableQuestions.size() < numberOfQuestion)
          throw NotEnoughQuestionsException();

      List<Question> questionsForUserMode = getQuestionsFromMode(
                        availableQuestions, quizDifficulty); 

       // sort this questionsForUserMode by Difficulty using comprator
  }

  // please put these magic numbers in constant fields or enum :)
  public static List<Question> getQuestionsFromMode (List<Question> questions,
             int mode) {
    if ( mode == 1 ) {
      return getQuestionsWithCertainLevel(questions, 1, 8);
    }
    else if ( moode == 2 ) {
      return getQuestionsWithCertainLevel(questions, 2, 9);
    }
    else
      return getQuestionsWithCertainLevel(questions, 3, 10);
  }

  private static List<Question> getQuestionsWithCertainLevel(
          List<Question> questions, int fromLeve, int toLevel) {
    List<Question> subQuestions = new ArrayList<Question>();

    for(Question question: questions) {
      if ( question.getDifficulty() >= fromLevel &&
           question.getDifficulty() <= toLevel ) {
        subQuestions.add(question);
      }
    }

    return subQuestions;
  }
于 2012-04-09T19:12:29.800 回答
1

我可能会首先在要求之后对问题进行排序,为不同的级别实现不同的排序算法(将当前难度级别最相关的问题放在第一位)。然后只是从列表的开头开始选择问题。

像这样的东西:

static final int[] easy = {1,2,3,4,5,6,7};
static final int[] medium = {3,4,5,6,7,8};
static final int[] hard = {4,5,6,7,8,9,10};

public static List<Question> getQuestions(List<Question> availableQuestions,
        int quizDifficulty, int numberOfQuestion){

     if(quizDifficulty == 0) // Easy
         Collections.sort(availableQuestions, new CompareQuestion(easy));
     else if(quizDifficulty == 2) // Hard
         Collections.sort(availableQuestions, new CompareQuestion(hard));
     else if(quizDifficulty == 1) // Normal
         Collections.sort(availableQuestions, new CompareQuestion(medium));

    int questions  = availableQuestions.size();
    return availableQuestions.subList(0, numberOfQuestion <= questions ? numberOfQuestion : questions);
}

static class CompareQuestion implements Comparator<Question>{

    final int[] compareList;

    public CompareQuestion(int[] compareList){
        this.compareList = compareList;
    }

    @Override
    public int compare(Question q1, Question q2) {
        boolean o1wanted = inList(q1.difficulty, compareList);
        boolean o2wanted = inList(q2.difficulty, compareList);

        if(o1wanted && o2wanted) return 0;

        if(o1wanted && !o2wanted) return -1;

        return 1;
    }

    public boolean inList(int a, int[] list){
        for(int i : list) if(a == i) return true;
        return false;
    }
}
于 2012-04-09T17:44:16.160 回答
1

这就是我会做的。

  1. 在问题列表上开始循环。
  2. 根据 EASY:NORMAL:HARD 的条件,我会将它们添加到列表中
    • 如果(容易)
      • 如果(难度 < 8 )
      • 添加到列表中。....对于困难和正常来说也是如此。
  3. 最后,我将使用其中一种排序算法对子列表进行排序。

在这种情况下,如果未达到指定的难度级别,那么您最终会得到一个空的问题列表(例如,您提到的问题,即如果所有问题的难度级别都为 1 并且您请求困难难度)。

于 2012-04-09T18:02:57.053 回答
0

希望我阅读您的问题是正确的。我的建议是用这种格式做一些事情:

level|question

然后当您的问题被推入数组时,将级别与问题分开。

我不知道Java,但这是objective-c的想法

NSArray* components = [string componentsSeparatedByString:@"|"];
NSString* level = [components objectAtIndex:0];
NSString* question = [components objectAtIndex:1];

然后比较如果level == selectedLevel

考虑到你的问题和它的水平是并排的,我总是觉得这是最简单的,不用担心问题和它的水平不匹配。

于 2012-04-09T17:50:05.737 回答
0

我已经实现了自己的算法,它运行得非常完美,尽管它有很多重复的代码:

public static List<Question> getQuestions(List<Question> availableQuestions,
                                      int quizDifficulty, int numberOfQuestion)
{
    if(availableQuestions.size() < numberOfQuestion)
        throw NotEnoughQuestionsException();

    List<Question> questions = new ArrayList<Question>(numberOfQuestion);
    Map<Integer, List<Question>> map = new HashMap<Integer, List<Question>>();
    for(int i = 1; i <= 10; i++) map.put(i, new ArrayList<Question>());
    for(Question question : availableQuestions) 
    map.get(question.getDifficulty()).add(question);

    int L1 = map.get(1).size(); // number of questions with level 1
    int L2 = map.get(2).size();
    int L3 = map.get(3).size();
    int L4 = map.get(4).size();
    int L5 = map.get(5).size();
    int L6 = map.get(6).size();
    int L7 = map.get(7).size();
    int L8 = map.get(8).size();
    int L9 = map.get(9).size();
    int L10 = map.get(10).size();

    final int L1_TO_L8  = 0;
    final int L1_TO_L9  = 1;
    final int L1_TO_L10 = 2;
    final int L2_TO_L9  = 3;
    final int L2_TO_L10 = 4;
    final int L3_TO_L10 = 5;

    int status;

    if(difficulty == 0) // Easy (level 1 to level 8)
    {
        int missing = questionsCount - (L1+L2+L3+L4+L5+L6+L7+L8);
        if(missing > 0) // not enough questions in L1 through L8
        {
            if(missing - L9 > 0) // we must include all the level
            {
                status = L1_TO_L10;
            }
            else // enough questions in L1 through L9
            {
                status = L1_TO_L9;
            }
        }
        else // enough questions in L1 through L8
        {
            status = L1_TO_L8;
        }
    }
    else if(difficulty == 2) // Hard (level 3 to level 10)
    {
        int missing = questionsCount - (L3+L4+L5+L6+L7+L8+L9+L10);
        if(missing > 0) // not enough questions in L3 through L10
        {
            if(missing - L2 > 0) // we must include all the level
            {
                status = L1_TO_L10;
            }
            else // enough questions in L2 through L10
            {
                status = L2_TO_L10;
            }
        }
        else // enough questions in L3 through L10
        {
            status = L3_TO_L10;
        }
    }
    else /*if(difficulty == 1)*/ // Normal (level 2 to level 9)
    {
        int missing = questionsCount - (L2+L3+L4+L5+L6+L7+L8+L9);
        if(missing > 0) // not enough questions in L2 through L9
        {
            if(missing - L1 > 0) // we must include all the level
            {
                status = L1_TO_L10;
            }
            else // enough questions in L1 through L9
            {
                status = L1_TO_L9;
            }
        }
        else // enough questions in L2 through L9
        {
            status = L2_TO_L9;
        }
    }

    if(status == L1_TO_L8) // Look into level 1 through level 8 only
    {
        int q = 0;
        for(int level = 1; level <= 8 && q < numberOfQuestion; level += 8 * q <= numberOfQuestion * level? 0 : 1)
        {
            if(level == 1)
            {
                if(check(readyQuestionsList, map, 1)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
            }
            else if(level == 2)
            {
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
            }
            else if(level == 3)
            {
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
            }
            else if(level == 4)
            {
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
            }
            else if(level == 5)
            {
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
            }
            else if(level == 6)
            {
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
            }
            else if(level == 7)
            {
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
            }
            else if(level == 8)
            {
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
            }
        }
    }
    else if(status == L1_TO_L9)
    {
        int q = 0;
        for(int level = 1; level <= 9 && q < numberOfQuestion; level += 9 * q <= numberOfQuestion * level? 0 : 1)
        {
            if(level == 1)
            {
                if(check(readyQuestionsList, map, 1)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
            }
            else if(level == 2)
            {
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
            }
            else if(level == 3)
            {
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
            }
            else if(level == 4)
            {
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
            }
            else if(level == 5)
            {
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
            }
            else if(level == 6)
            {
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
            }
            else if(level == 7)
            {
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
            }
            else if(level == 8)
            {
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
            }
            else if(level == 9)
            {
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 1)){q++; continue;}
            }
        }
    }
    else if(status == L2_TO_L9)
    {
        int q = 0;
        for(int level = 2; level <= 9 && q < numberOfQuestion; level += 9 * q <= numberOfQuestion * level? 0 : 1)
        {
            if(level == 2)
            {
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
            }
            else if(level == 3)
            {
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
            }
            else if(level == 4)
            {
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
            }
            else if(level == 5)
            {
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
            }
            else if(level == 6)
            {
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
            }
            else if(level == 7)
            {
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
            }
            else if(level == 8)
            {
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
            }
            else if(level == 9)
            {
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
            }
        }
    }
    else if(status == L2_TO_L10)
    {
        int q = 0;
        for(int level = 2; level <= 10 && q < numberOfQuestion; level += 10 * q <= numberOfQuestion * level? 0 : 1)
        {
            if(level == 2)
            {
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
            }
            else if(level == 3)
            {
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
            }
            else if(level == 4)
            {
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
            }
            else if(level == 5)
            {
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
            }
            else if(level == 6)
            {
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
            }
            else if(level == 7)
            {
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
            }
            else if(level == 8)
            {
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
            }
            else if(level == 9)
            {
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
            }
            else if(level == 10)
            {
                if(check(readyQuestionsList, map, 10)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 2)){q++; continue;}
            }
        }
    }
    else if(status == L3_TO_L10)
    {
        int q = 0;
        for(int level = 3; level <= 10 && q < numberOfQuestion; level += 10 * q <= numberOfQuestion * level? 0 : 1)
        {
            if(level == 3)
            {
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
            }
            else if(level == 4)
            {
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
            }
            else if(level == 5)
            {
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
            }
            else if(level == 6)
            {
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
            }
            else if(level == 7)
            {
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
            }
            else if(level == 8)
            {
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
            }
            else if(level == 9)
            {
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 10)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
            }
            else if(level == 10)
            {
                if(check(readyQuestionsList, map, 10)){q++; continue;}
                if(check(readyQuestionsList, map, 9)){q++; continue;}
                if(check(readyQuestionsList, map, 8)){q++; continue;}
                if(check(readyQuestionsList, map, 7)){q++; continue;}
                if(check(readyQuestionsList, map, 6)){q++; continue;}
                if(check(readyQuestionsList, map, 5)){q++; continue;}
                if(check(readyQuestionsList, map, 4)){q++; continue;}
                if(check(readyQuestionsList, map, 3)){q++; continue;}
            }
        }
    }
    else /*if(status == L1_TO_L10)*/
    {
        // same idea is implemented here
    }
    return questions;
}

private boolean check(List<Question> readyQuestionsList, Map<Integer, List<Question>> map, int level)
{
    if(map.get(level).size() > 0 && map.get(level).get(0) != null)
    {
        readyQuestionsList.add(map.get(level).remove(0));
        return true;
    }
    return false;
}
于 2012-04-09T23:33:20.567 回答