#36378: WA(line:12)


jacklyntsai1213@gmail.com (Jacklyn Tsai)

學校 : 臺北市立第一女子高級中學
編號 : 234318
來源 : [150.116.179.53]
最後登入時間 :
2023-07-21 18:57:40
c086. 00402 - M*A*S*H -- UVa402 | From: [150.116.179.53] | 發表日期 : 2023-07-16 10:15

求大神指點程式哪裡出錯🙏

#0: 100% WA (line:12)

您的答案為: 1
正確答案為: 1 2 3

#include <bits/stdc++.h>
using namespace std;


int main() {
  int selection = 1;
  int n,x, card[20];
  while (cin>>n){
    vector<int> line;
    for(int i=1; i<=n; i++){
      line.push_back(i);
    }
    cin>> x;
    
    
    bool done = false;
    
    // special case: if n==x
    if (n == x){
      goto PrintAns;
    }
    
    // drawing cards
    for(int i=0; i<20; i++)
      cin>>card[i];
    
    for(int i=0; i<20; i++){
      auto it = line.begin()+card[i]-1;
      // simulating elimination
      while(it < line.end()){
        // Due to deletion in loop, iterator became
            // invalidated. So reset the iterator to next item.
        it = line.erase(it);
        it += card[i]-1;

        // checks if reached enough ppl with every elimination
        if (line.size() == x){
          done= true;
          break;
        }
      }

      if (done)
        break;
    }

    PrintAns: 
    cout<< "Selection #"<< selection++ <<endl;
    for(int i=0; i< line.size(); i++){
      if (i==line.size()-1)
        cout<< line[i]<< endl;
      else
        cout<< line[i]<< " ";
    }
    cout<< endl;
  }
}


 
ZeroJudge Forum