Skip to main content
added 279 characters in body
Source Link
user12205
  • 9k
  • 3
  • 32
  • 65

C, 121

I present a 128-char C solution without usingThis is quite long compared to other entries, but it does not rely on any built-in sorting andor ToLower functions:

i,j;main(k){char s[99];gets(s);for(;i<strlen(s);){j=i-1;k=s[i++];while(j>=0&&(s[j]|32)>(k|32))s[j+1]=s[j--];s[j+1]=k;}puts(s);}
j;main(k){char s[99],*p=s;gets(s);while(*p){j=p-s-1;k=*p++;while(j>=0&&(s[j]|32)>(k|32))s[j+1]=s[j--];s[j+1]=k;}puts(s);}

More readable version:

i,j; main(k) {
    char s[99];
    gets(s);
    for(;i<strlen(s);) {
        j=i-1;
        k=s[i++];
        while( j>=0 && (s[j]|32)>(k|32) )
            s[j+1]=s[j--];
        s[j+1]=k;
    }
    puts(s);
}
j; main(k) {
    char s[99], *p=s;
    gets(s);
    while(*p) {
        j = p-s-1;
        k = *p++;
        while(j >= 0 && (s[j]|32) > (k|32))
            s[j+1] = s[j--];
        s[j+1] = k;
    }
    puts(s);
}

This is an implementation of insertion sort with a case-insensitive comparison between elements (using the |32 bitwise operation). This is because in ASCII encoding uppercase letters and lowercase letters only differ by the 25 bit.

I present a 128-char C solution without using any built-in sorting and ToLower functions:

i,j;main(k){char s[99];gets(s);for(;i<strlen(s);){j=i-1;k=s[i++];while(j>=0&&(s[j]|32)>(k|32))s[j+1]=s[j--];s[j+1]=k;}puts(s);}

More readable version:

i,j; main(k) {
    char s[99];
    gets(s);
    for(;i<strlen(s);) {
        j=i-1;
        k=s[i++];
        while( j>=0 && (s[j]|32)>(k|32) )
            s[j+1]=s[j--];
        s[j+1]=k;
    }
    puts(s);
}

C, 121

This is quite long compared to other entries, but it does not rely on any built-in sorting or ToLower functions:

j;main(k){char s[99],*p=s;gets(s);while(*p){j=p-s-1;k=*p++;while(j>=0&&(s[j]|32)>(k|32))s[j+1]=s[j--];s[j+1]=k;}puts(s);}

More readable version:

j; main(k) {
    char s[99], *p=s;
    gets(s);
    while(*p) {
        j = p-s-1;
        k = *p++;
        while(j >= 0 && (s[j]|32) > (k|32))
            s[j+1] = s[j--];
        s[j+1] = k;
    }
    puts(s);
}

This is an implementation of insertion sort with a case-insensitive comparison between elements (using the |32 bitwise operation). This is because in ASCII encoding uppercase letters and lowercase letters only differ by the 25 bit.

Source Link
user12205
  • 9k
  • 3
  • 32
  • 65

I present a 128-char C solution without using any built-in sorting and ToLower functions:

i,j;main(k){char s[99];gets(s);for(;i<strlen(s);){j=i-1;k=s[i++];while(j>=0&&(s[j]|32)>(k|32))s[j+1]=s[j--];s[j+1]=k;}puts(s);}

More readable version:

i,j; main(k) {
    char s[99];
    gets(s);
    for(;i<strlen(s);) {
        j=i-1;
        k=s[i++];
        while( j>=0 && (s[j]|32)>(k|32) )
            s[j+1]=s[j--];
        s[j+1]=k;
    }
    puts(s);
}