Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #ifndef DEBUG
- #define DEBUG(...) printf(__VA_ARGS__)
- #endif
- void strip(char **first, char **last, char *chars) {
- //int len = *last - *first;
- char *tmp = chars;
- while(*tmp){
- char *tmp2 = chars;
- while(*tmp2){
- if (**first == *tmp2 && **last == *tmp2)
- {
- *first += 1;
- *last -= 1;
- //printf("test\n");
- }
- if (**first == *tmp2)
- {
- *first += 1;
- }
- if (**last == *tmp2){
- *last -= 1;
- }
- tmp2++;
- }
- tmp++;
- }
- }
- int main() {
- int n, q;
- char *s, *chars;
- scanf("%d%d", &n, &q);
- s = malloc((n+1) * sizeof(char));
- chars = malloc(26 * sizeof(char));
- scanf("%s", s);
- for (int i = 0; i < q; ++i) {
- char *first = s, *last = s+n;
- scanf("%s", chars);
- strip(&first, &last, chars);
- // ispisuje znakovni niz duljine last-first počevši od pokazivača first
- printf("%d %.*s\n", (int)(last-first), (int)(last-first), first);
- }
- free(s);
- free(chars);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement