Submission #4962987


Source Code Expand

S = gets.chomp

alphabet = Array.new(26) {0}

S.chars.each do |c|
  alphabet[c.ord - 'a'.ord] += 1
end

if S.size != 26
  min = alphabet.find_index {|a| a == 0}
  char = ('a'.ord + min).chr
  puts S + char
else
  index = S.size - 1
  (S.size - 1).downto(1) do |i|
    if S[i] < S[i-1]
      index = i - 1
    else
      break
    end
  end

  if index == 0
    puts -1
  elsif index == 1
    puts (S[index-1].ord + 1).chr
  else

    ch = S[-1]
    index.upto(S.size-2) do |i|
      if S[index-1] > S[i]
        ch = S[i-1]
        break
      end
    end

    puts S[0..index-2] + ch
  end
end

Submission Info

Submission Time
Task A - Diverse Word
User h_izu
Language Ruby (2.3.3)
Score 300
Code Size 634 Byte
Status AC
Exec Time 7 ms
Memory 3836 KB

Compile Error

./Main.rb:24: warning: ambiguous first argument; put parentheses or a space even after `-' operator

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 23
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt AC 7 ms 1788 KB
02.txt AC 7 ms 1788 KB
03.txt AC 7 ms 1788 KB
04.txt AC 7 ms 1788 KB
05.txt AC 7 ms 1788 KB
06.txt AC 7 ms 1788 KB
07.txt AC 7 ms 1788 KB
08.txt AC 7 ms 1788 KB
09.txt AC 7 ms 1788 KB
10.txt AC 7 ms 1788 KB
11.txt AC 7 ms 1788 KB
12.txt AC 7 ms 1788 KB
13.txt AC 7 ms 1788 KB
14.txt AC 7 ms 3836 KB
15.txt AC 7 ms 1788 KB
16.txt AC 7 ms 1788 KB
17.txt AC 7 ms 1788 KB
18.txt AC 7 ms 1788 KB
19.txt AC 7 ms 1788 KB
s1.txt AC 7 ms 1788 KB
s2.txt AC 7 ms 1788 KB
s3.txt AC 7 ms 1788 KB
s4.txt AC 7 ms 1788 KB