CSES - Datatähti 2018 loppu - Results
Submission details
Task:Merkkijono
Sender:Olli
Submission time:2018-01-18 14:41:57 +0200
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.05 sdetails
#3ACCEPTED0.04 sdetails
#4ACCEPTED0.04 sdetails
#5ACCEPTED0.04 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:80:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < oper.size(); ++i) {
                   ^

Code

#include <iostream>
#include <vector>
#include <deque>

using namespace std;

vector<string> oper;
deque<char> q;


int n = 26;


bool inOrder() {
	for(deque<char>::iterator it = q.begin() + 1; it != q.end(); ++it) {
		char a = *it;
		char b = *(it - 1);
		if((int) b > (int) a) {
			return false;
		}
	}
	return true;
	

}


void swap() {
	char a = *q.begin();
	char b = *(q.begin() + 1);
	oper.push_back("SWAP");
	q.erase(q.begin());
	q.erase(q.begin());
	q.insert(q.begin(), a);
	q.insert(q.begin(), b);


}


void move() {
	oper.push_back("MOVE");
	char c = *(q.end() - 1);
	q.erase(q.end() - 1);
	q.insert(q.begin(), c);
}

void swapTwoConsecutives(int a) {
	for(int i = n - a; i >= 0; --i) {
		move();
	}
	swap();
	for(int i = a - 1; i > 0; --i) {
		move();
	}


}


int main() {
	string s;
	cin >> s;
	for(int i = 0; i < n; ++i) {
		q.insert(q.end(), s[i]);
	}


	for(int times = 1; times <= n; ++times) {
		for(int i = 1; i < n; ++i) {
			deque<char>::iterator it = q.begin() + i;
			char a = *it;
			char b = *(it - 1);
			if((int) a < (int) b) {
				swapTwoConsecutives(i);
			}
		}
	}
	cout << oper.size() << "\n";
	for(int i = 0; i < oper.size(); ++i) {
		cout << oper[i] << "\n";
	}

	/*for(deque<char>::iterator it = q.begin(); it != q.end(); ++it) {
		cout << *it;
	}
	cout << "\n";
	*/
}


Test details

Test 1

Verdict: ACCEPTED

input
ABCDEFGHIJKLMNOPQRSTUVWXYZ

correct output
0

user output
0

Test 2

Verdict: ACCEPTED

input
ZYXWVUTSRQPONMLKJIHGFEDCBA

correct output
923
MOVE
MOVE
SWAP
MOVE
...

user output
8775
MOVE
MOVE
MOVE
MOVE
...

Test 3

Verdict: ACCEPTED

input
RPJMFWBHYQOTXUAENLDGZISCVK

correct output
611
SWAP
MOVE
MOVE
SWAP
...

user output
4617
MOVE
MOVE
MOVE
MOVE
...

Test 4

Verdict: ACCEPTED

input
GWJSPBHANMXYFLKIDORVUCEZQT

correct output
659
MOVE
SWAP
MOVE
SWAP
...

user output
3861
MOVE
MOVE
MOVE
MOVE
...

Test 5

Verdict: ACCEPTED

input
BJYNFLKEIUCZMQHRAXOGWPSDTV

correct output
624
MOVE
SWAP
MOVE
SWAP
...

user output
3564
MOVE
MOVE
MOVE
MOVE
...