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

Code

#include <bits/stdc++.h>

using namespace std;

const int n = 26;

int main(){
  char chars[n];
  char c2[n];
  for(int i = 0; i < n; i++){
    char c;
    cin >> c;
    chars[i] = c;
    c2[i] = c;
  }
  int moves = 0;
  bool done = false;
  while(!done){
    done = true;
    for(int i = 0; i < n-1; i++){
      if(c2[i] > c2[i+1]){
        int t = c2[i];
        c2[i] = c2[i+1];
        c2[i+1] = t;
        done = false;
        moves++;
      }
  }
  }
  cout << (moves * (n+1)) << endl;
  done = false;
  while(!done){
    done = true;
    for(int i = 0; i < n-1; i++){
      if(chars[i] > chars[i+1]){
        for(int t = 0; t < n-i; t++)
          cout << "MOVE" << endl;
        cout << "SWAP" << endl;
        for(int t = n-i; t < n; t++)
          cout << "MOVE" << endl;
        int t = chars[i];
        chars[i] = chars[i+1];
        chars[i+1] = t;
        done = false;
      }
    }
  }
}

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
...