CSES - Datatähti 2017 alku - Results
Submission details
Task:Järjestys
Sender:Hupijekku
Submission time:2016-10-06 13:30:57 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:26:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (numbers[j] == i && (j + 1) != i)
                      ^
input/code.cpp:30:6: error: 'reverse' is not a member of 'std'
      std::reverse(numbers.begin(), numbers.end() - (n - j - 1));
      ^
input/code.cpp:33:5: error: 'reverse' is not a member of 'std'
     std::reverse(numbers.begin(), numbers.end() - (n - i));
     ^

Code

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

int main()
{
	int numberAmount;
	std::cin >> numberAmount;
	std::cin.ignore(1, '\n');
	std::string sNumbers;
	std::getline(std::cin, sNumbers);
	std::istringstream is(sNumbers);
	int x;
	std::vector<int> numbers;
	while (is >> x)
	{
		numbers.push_back(x);
	}
	std::vector<int> rotates;
	unsigned int n = numbers.size();
	for (unsigned int i = n; i > 0; i--)
	{
		for (unsigned int j = 0; j < i; j++)
		{
			if (numbers[j] == i && (j + 1) != i)
			{
				if (j > 0) 
				{
					std::reverse(numbers.begin(), numbers.end() - (n - j - 1));
					rotates.push_back(j + 1);
				}
				std::reverse(numbers.begin(), numbers.end() - (n - i));
				rotates.push_back(i);
			}
		}
	}
	std::cout << rotates.size() << '\n';
	for (unsigned int x = 0; x < rotates.size(); x++)
	{
		std::cout << rotates[x] << " ";
	}
    return 0;
}