【问题标题】:[C++14]I'm using pair but no output[C++14]我正在使用pair但没有输出
【发布时间】:2016-07-21 01:59:22
【问题描述】:

我正在编写一个代码来使用“pair”对数字进行排序和输出。 我尝试了一些案例,但没有输出。 我应该如何重写代码?

#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main()
{
    int k, i, n;
    cin >> n;
    pair<int, int> a[n];
    for (i = 0; i < n; i++) {
        cin >> k;
        a[i].first = -k;
        a[i].second = i + 1;
    }
    sort(a, a + n);
    for (i = 0; i++; i < n) {
        cout << a[i].second;
    }
}

【问题讨论】:

  • 打开你的警告:警告:对于增量表达式没有效果[-Wunused-value]

标签: c++ sorting c++14 std-pair


【解决方案1】:
for(i=0;i++;i<n){

你的意思是这样写的:

for(i=0;i<n;i++){

【讨论】:

  • 谢谢!输入很困难……
  • @YasushiMatsushima 如果答案正确,请考虑将其标记为“已接受”
猜你喜欢
  • 2015-12-22
  • 1970-01-01
  • 2022-01-24
  • 2021-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多