Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6235729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:43:16+00:00 2026-05-24T10:43:16+00:00

I am getting RUN FAILED (exit value 1, total time: 493ms) . I get

  • 0

I am getting RUN FAILED (exit value 1, total time: 493ms). I get it when I try to check if a vector has an element from an array in it:

if (find(cycles.begin(), cycles.end(), permutation[i]) == cycles.end()) {
     startCycle = permutation[i];
     break;
}

The full code of the program:

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define TESTING_FILE_IN
//#define TESTING_FILE_OUT
#define DEBUG
//#define SHOW_TIMING

vector< int > cycles;
int permutation[1001];

/*
 * 
 */
int main() {

    #ifdef TESTING_FILE_IN
    freopen("in.txt", "r", stdin);
    #endif

    int ind, startCycle, n, count, elemProc;

    scanf("%d", &n); //Number of elements in the permutation

    for (int i = 0; i < n; i++) {
        cin >> permutation[i];
    }   

    // Calculate cycles
    startCycle = 1;
    while (true) {
        cycles.push_back(ind + 1);
        elemProc++;
        ind = permutation[ind] - 1;
        if (ind == startCycle) {
            cycles.push_back(startCycle);
            cycles.push_back(-1);
            count++;
            for (int i = 0; i < n; i++) {
                if (find(cycles.begin(), cycles.end(), permutation[i]) == cycles.end()) {
                    startCycle = permutation[i];
                    break;
                }
            }
        }
        if (elemProc == n)
            break;
    }

    cout << count << endl;
    for (int i = 0; i < cycles.size(); ++i) {
        if (cycles[i] != -1)
            cout << cycles[i] << " ";
        else
            cout << endl;
    }

    return 0;
}

When I comment a piece of code that does the searching, it builds and runs okay. Hope you’ll be able to help me. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:43:16+00:00Added an answer on May 24, 2026 at 10:43 am

    You might think that local variables automatically have initial value of zero when you define them. That’s not the case. For a non-static local variable of build-in type without an initializer, its initial value can be anything.

           v----you should initialize these local variables
       int ind, startCycle, n, count, elemProc;
    

    You may define them as

       int ind = 0, startCycle = 0, n = 0, count = 0, elemProc = 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this following error during run time. ERROR: thread attach failed My
I am getting this run time error when using IID_IWebBrowser2 interface of CLSID_InternetExplorer. Run-Time
I'm getting the following exception when I run my application in Release mode from
I am getting an error when trying to run my web application from IIS
At the moment I am getting a KrbException: Integrity check on decrypted field failed
For whatever reason, when I try to run any integration test, I'm getting the
I am getting when I try to run jiewmeng@klifmedia:~/cloud9$ sudo bin/cloud9.sh [sudo] password for
This code snippet isn't working, I'm getting an Authentication Failed. response from the server.
I am getting the following error: Conversion failed when converting the varchar value '2010-01-10'
This is the exception that I am getting when I run my application with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.