CSES - Datatähti 2017 alku - Results
Submission details
Task:Järjestys
Sender:Shrike
Submission time:2016-10-10 20:14:39 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void reverse(int*, int, int)':
input/code.cpp:14:10: warning: statement has no effect [-Wunused-value]
     for(i;i<--num;i++)
          ^
input/code.cpp: In function 'int main()':
input/code.cpp:56:19: error: variable-sized object 'job' may not be initialized
  int job[2*c] = {0};
                   ^
input/code.cpp:61:14: warning: unused variable 'j' [-Wunused-variable]
  int inp, i, j;
              ^

Code

#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <cmath>

using namespace std;

void
reverse (int *list, int length, int num)
{
    int swap;
    int i=0;
    for(i;i<--num;i++)
    {
        swap=list[i];
        list[i]=list[num];
        list[num]=swap;
    }
}

int
atoi (string c)
{
	stringstream s;
	int i;
	s << c;
	s >> i;
	return i;
}

vector<int>
into_vec (string str, int size)
{
	vector<int> vec(size);
	istringstream ssin(str);
        int input, j = 0;
        while(ssin >> input) {
            vec[j] = input;
	    j++;
        }
	return vec;
}

int
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string in;
	int c;
	
	getline (cin, in);
	c = atoi (in);
	int vec[c];
	int job[2*c] = {0};

	getline (cin, in);

	istringstream ssin(in);
	int inp, i, j;

	i = 0;
	while (ssin >> inp) {
		vec[inp-1] = i;
		i++;
	}
	cout << 2*c << "\n";
	int n = 0;
	for (i = c; i > 0; i--) {
		if (vec[i-1] == i) {
			cout << "1 1 ";
		} else {
			int plc = vec[i-1];
			int j;
			for (j = 0; j < n; j++)
				plc = (int)abs((double)(plc-job[j]));
			cout << plc+1 << " " << i << " ";
			job[n] = plc+1;
			n++;
			job[n] = i;
			n++;
		}
	}
	cout << "\n";
	return 0;
}