CSES - Datatähti 2018 loppu - Results
Submission details
Task:Merkkijono
Sender:Olli
Submission time:2018-01-18 13:10:55 +0200
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#20.95 sdetails
#3--details
#40.96 sdetails
#50.96 sdetails

Compiler report

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

Code

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

using namespace std;

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

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;
	

}


int main() {
	string s;
	cin >> s;
	int n = 26;
	int moves = 0;
	for(int i = 0; i < n; ++i) {
		q.insert(q.end(), s[i]);
	}
	while(!inOrder()) {
		//cout << s << "\n";
		char a = *q.begin();
		char b = *(q.begin() + 1);
		if((int) a > b) {
			oper.push_back("SWAP");
			q.erase(q.begin());
			q.erase(q.begin());
			q.insert(q.begin(), a);
			q.insert(q.begin(), b);
		}
		char c = *(q.end() - 1);
		q.erase(q.end() - 1);
		q.insert(q.begin(), c);
		oper.push_back("MOVE");
	} 


	cout << oper.size() << "\n";

	for(int i = 0; i < oper.size(); ++i) {
		cout << oper[i] << "\n";
	}


}


Test details

Test 1

Verdict: ACCEPTED

input
ABCDEFGHIJKLMNOPQRSTUVWXYZ

correct output
0

user output
0

Test 2

Verdict:

input
ZYXWVUTSRQPONMLKJIHGFEDCBA

correct output
923
MOVE
MOVE
SWAP
MOVE
...

user output
(empty)

Test 3

Verdict:

input
RPJMFWBHYQOTXUAENLDGZISCVK

correct output
611
SWAP
MOVE
MOVE
SWAP
...

user output
(empty)

Test 4

Verdict:

input
GWJSPBHANMXYFLKIDORVUCEZQT

correct output
659
MOVE
SWAP
MOVE
SWAP
...

user output
(empty)

Test 5

Verdict:

input
BJYNFLKEIUCZMQHRAXOGWPSDTV

correct output
624
MOVE
SWAP
MOVE
SWAP
...

user output
(empty)