Little_White_x
2017-08-12 09:30
采纳率: 50%
浏览 5.1k

vs2017编译报错,变量未初始化?

今天在写atcoder contest 080E - Young Maids时,在我的solve()函数里面总是说我的
down没有初始化,但是我明明在循环里面初始化了啊?
附上代码:

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

vector<int> ans;
int n;
const int INF = 0x3f3f3f;

void solve(vector<int> dir,int f,int s)
{
    if (dir.empty()) return;
    int maxhead = 0, cnt = 0,down;
    for (int i = 0; i < dir.size()-1; ++i) {
        if (dir[i] != f && dir[i] != s) {
            if (dir[i + 1] != f && dir[i + 1] != s) {
                if (dir[i] > maxhead) {
                    cout << "ok" << endl;
                    cout << i << endl;
                    maxhead = dir[i];
                    down = i;
                }
            }
        }
    }
    cout << down << endl;

    ans.push_back(dir[down + 1]); ans.push_back(dir[down]);
    vector<int> nex;
    for (int i = 0; i < dir.size(); ++i) {
        if (i != down && i!=down+1) {
            nex.push_back(dir[i]);
        }
    }
    solve(nex, f, s);
}

int main()
{
    vector<int> iv; int temp,goalf=INF,goals=INF;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        iv.push_back(temp);
        if (temp < goalf && !(i%2)) {
            goalf = temp;
        }
    }
    int i;
    for (i = 0; iv[i] != goalf; ++i);
    for (int j = i + 1; j < n; ++j) {
        if (iv[j] < goals) {
            goals = iv[j];
        }
    }

    cout << goalf << " " << goals << endl;

    solve(iv,goalf,goals);
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); ++i) {
        cout << ans[i] << " ";
    }
    cout << endl;
    system("pause");
    return 0;
}

望各位能指点一二,谢了

4条回答 默认 最新

相关推荐 更多相似问题