Curz酥 2022-07-26 11:33 采纳率: 90.9%
浏览 24
已结题

PAT乙级一题不明白为什么WA

题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/1478634461852217344

以下是我的C++代码,我不明白明明输出结果和答案一模一样,还测了几组样例,结果答案还是0分:


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

int N, M, max_weigh = 0, weigh;

int main() {
    vector<int> top_weigh;
    cin >> N >> M;
    while (N--) {
        for (int i = 0; i < M; i++) {
            cin >> weigh;
            if (weigh > max_weigh) max_weigh = weigh;
        }
        top_weigh.push_back(max_weigh);
        max_weigh = 0;
    }
    int idx = 1;
    for (auto i : top_weigh) {
        cout << i << " "[idx++ > N];
    }
    cout << "\n";
    cout << *max_element(top_weigh.begin(), top_weigh.end());
    
    return 0;
}

```

  • 写回答

1条回答 默认 最新

  • 快乐鹦鹉 2022-07-26 11:42
    关注

    for (auto i : top_weigh) {
    cout << i << " "[idx++ > N];
    }
    这样的话,每个值后面都带了一个空格,正确答案可能是最后一个值后面是没有空格的
    ===
    [idx++ > N]这个写法还没见过,啥作用

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 8月3日
  • 已采纳回答 7月26日
  • 创建了问题 7月26日