Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #define N 10000
- void getstr(char s[]) {
- char c;
- int i = 0;
- while((c = getchar()) != '\n')
- s[i++] = c;
- s[i] = '\0';
- }
- char *expandChars(char s[]) {
- static char ans[N];
- int i = 0, k = 0;
- char start, end, c;
- for (i = 0; s[i] != '\0'; i++) {
- if ((s[i] == '-' && i > 0 && s[i + 1] != '\0') &&
- (isdigit(s[i - 1]) && isdigit(s[i + 1]) ||
- (isalpha(s[i - 1]) && isalpha(s[i + 1]) &&
- (islower(s[i - 1]) && islower(s[i + 1]) ||
- isupper(s[i - 1]) && isupper(s[i + 1]))))) {
- start = s[i - 1];
- end = s[i + 1];
- for (c = (start < end) ? (start + 1) : (start - 1);
- c != end;
- (start < end) ? c++ : c--)
- ans[k++] = c;
- } else {
- ans[k++] = s[i];
- }
- }
- return ans;
- }
- int main() {
- char s1[N];
- getstr(s1);
- char *s2 = expandChars(s1);
- printf("%s", s2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment