Submission #1575971


Source Code Expand

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.range;

  auto str=readln.chomp.to!(char[]);

  int[char] cnt;
  foreach(c; str){
    if(!(c in cnt)) cnt[c]=1;
  }

  bool g(char[] s){
    char tg=s[0];
    bool ok=true;
    foreach(c; s) ok&=(c==tg);
    return ok;
  }

  int f(char c, char[] s){
    int ret=0;
    while(!g(s)){
      foreach(i; 0..(s.length-1)){
        if(s[i+1]==c) s[i]=c;
      }
      /* if(s.back!=c) */ s.popBack;
      ret++;
    }
    return ret;
  }

  int mi=str.length;
  foreach(c, v; cnt){
    mi=min(mi, f(c, str.dup));
  }

  writeln(mi);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Submission Info

Submission Time
Task A - Shrinking
User ikd
Language D (DMD64 v2.070.1)
Score 0
Code Size 803 Byte
Status CE

Compile Error

./Main.d(31): Error: cannot implicitly convert expression (str.length) of type ulong to int