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

Compiler report

input/code.cpp: In function 'bool inOrder(std::string)':
input/code.cpp:9:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < s.length() - 1; ++i) {
                   ^
input/code.cpp: In function 'int main()':
input/code.cpp:44:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < oper.size(); ++i) {
                   ^

Code

#include <iostream>
#include <vector>

using namespace std;

vector<string> oper;

bool inOrder(string s) {
	for(int i = 0; i < s.length() - 1; ++i) {
		if((int) s[i+1] < (int) s[i]) {
			return false;
		} 
	}

	return true;

}

int main() {
	string s;
	cin >> s;
	int n = 26;
	while(!inOrder(s)) {
		//cout << s << "\n";
		if((int) s[0] > (int) s[1]) {
			oper.push_back("SWAP");
			char a = s[0];
			s[0] = s[1];
			s[1] = a;
		} else {
			string newString = "";
			newString += s[n-1];
			for(int i = 0; i < n-1; ++i) {
				newString += s[i];
			}
			s = newString;
			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)