From a7cc187e2090a2cfa866dff07e6bbf703f06e2c8 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Fri, 3 Dec 2021 18:36:26 +0800 Subject: 3.3 --- 3/3.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 3/3.c (limited to '3/3.c') diff --git a/3/3.c b/3/3.c new file mode 100644 index 0000000..3921e02 --- /dev/null +++ b/3/3.c @@ -0,0 +1,38 @@ +#include +#include + +#define MAXLEN 1000 + +/* expands shorthand notation like a-z and 0-9 for ASCII charset */ +void expand(char s1[], char s2[]); + +int main(int argc, char *argv[]) { + int i; + char c, s1[MAXLEN], s2[MAXLEN]; + + for (i = 0; i < MAXLEN - 1 && (c = getchar()) != '\n' && c != EOF; i++) + s1[i] = c; + s1[i] = 0; + + expand(s1, s2); + printf("%s\n", s2); + + return 0; +} + +void expand(char s1[], char s2[]) { + int i, j, c; + + for (i = 0, j = 0; j < MAXLEN - 1 && (c = s1[i]) != 0; i++) { + if (c == '-' && i > 0 && isalnum(s1[i - 1]) && isalnum(s1[i + 1])) { + c = s1[i - 1] + 1; + while (c < s1[i + 1]) + s2[j++] = c++; + continue; + } + + s2[j++] = c; + } + + s2[j] = 0; +} \ No newline at end of file -- cgit v1.2.3