Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ Challenge 5: Optimize You're Quotes

Name: Anonymous 2018-01-08 14:27

INPUT: A multi-line string specifying quoted poasts on a 2ch-like board, one poast per line. Lines are prefixed with ``>>''.

OUTPUT: A single, optimized quote link, created by replacing consecutive poast numbers with a range.

EXAMPLE INPUT ⅰ
>>1
>>2
>>3

EXAMPLE OUTPUT ⅰ
>>1-3

EXAMPLE INPUT ⅱ
>>1
>>3
>>2
>>5

EXAMPLE OUTPUT ⅱ
>>1-3,5

EXAMPLE INPUT ⅲ
>>6
>>2
>>3
>>1
>>5

EXAMPLE OUTPUT ⅲ
>>1-3,5-6

🌑 In case of only two consecutive poasts, still replace them with a range.
🌑 Numbers are positive integers from 1 too 1001 (inclusive on both sides).
🌑 Use standard input and standard output as interfaces.
🌑 Shortest code wins. Good luck!

Name: Anonymous 2018-01-14 23:48

Finally got this piece of shit working:
#include <ctype.h>
#include <stdio.h>

i, c;
char t[1025];
main() {
for(c = 'x'; !feof(stdin); ) {
for(; !isdigit(c) && !feof(stdin); c = getchar());
for(i = 0; isdigit(c); c = getchar())
i = i * 10 + c - '0';
t[i%1024] = 1;
}
putchar('>');
for(i = c = 1; i < 1024; ++i) {
if(t[i]) {
printf("%c%d", ",>"[c], i);
for(; t[i+1]; ++i, c |= 2);
if(c & 2)
printf("-%d", i);
c = 0;
}
}
putchar('\n');
return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List