4 solutions

  • 0
    @ 2024-2-20 12:53:09

    偷懒用 string ,并且只交换行下标

    #include <bits/stdc++.h>
    using namespace std;
    
    #define DBG(x) cout << #x << "=" << x << endl
    
    const int N = 5;
    int idxs[] = {-1, 1, 2, 3, 4, 5};
    string g[N + 1];
    
    void solve() {
      int m, n;
    
      for (int i = 1; i <= N; i++)
        getline(cin, g[i]);
      cin >> m >> n;
      swap(idxs[m], idxs[n]);
    
      for (int i = 1; i <= N; i++)
        cout << g[idxs[i]] << endl;
    }
    
    int main() {
      solve();
    
      return 0;
    }
    

    Information

    ID
    86
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    4
    Tags
    # Submissions
    259
    Accepted
    119
    Uploaded By