CCF火车购票2

这个题吧以前写过很多次了,但是今天再做还是90分,想了半天,问题就在我标注三颗星的地方,之前写成了if,不是while,不知道是忽略了哪种情况QAQ,想不出来

#include
#include
#include
using namespace std;
int main()
{
    int n, p, Count = 1;
    queue Q[20];
    for(int i=0; i<20; i++)
    {
        for(int j=0; j<5; j++)
        {
            Q[i].push(Count++);
        }
    }
//    for(int i=0; i<20; i++)
//    {
//        while(!Q[i].empty())
//        {
//            cout << Q[i].front() << " ";
//            Q[i].pop();
//        }
//        cout << endl;
//    }
    cin >> n;
    while(n--)
    {
        cin >> p;
        int flag = 0;
        for(int i=0; i<20; i++)
        {
            if(Q[i].size()>=p)
            {
                for(int j=0; j                 {
                    cout << Q[i].front() << " ";
                    Q[i].pop();
                }
                cout << endl;
                flag = 1;
                break;
            }
        }
        if(!flag)
        {
                for(int j=0;j<20; j++)
                {
        while(!Q[j].empty())
        {
             cout << Q[j].front() << " ";
                Q[j].pop();
                p--;
                if(!p)
                    break;
        }
                }
                cout << "\n";
            }
        }
    return 0;
}
 

你可能感兴趣的:(CCF)