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 counterf = 0;
- //int counterl = 0;
- while(*chars){
- if(*chars == **first){
- //printf("JEDNAKI %c %d\n", *chars,counter);
- *first = *first + 1;
- if(**first){
- chars = chars - counterf;
- counterf = 0;
- }else break;
- }else{
- //printf("NEJEDNAKI %c\n", *chars);
- chars++;
- counterf++;
- }
- /*if(*chars == **last){
- *last = *last - 1;
- chars = chars - counterl;
- counterl = 0;
- }else{
- chars++;
- counterl++;
- }*/
- }
- }
- 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