Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #ifndef DEBUG
  5. #define DEBUG(...) printf(__VA_ARGS__)
  6. #endif
  7.  
  8. void strip(char **first, char **last, char *chars) {
  9. int counterf = 0;
  10. //int counterl = 0;
  11. while(*chars){
  12. if(*chars == **first){
  13. //printf("JEDNAKI %c %d\n", *chars,counter);
  14. *first = *first + 1;
  15.  
  16. if(**first){
  17. chars = chars - counterf;
  18. counterf = 0;
  19. }else break;
  20.  
  21. }else{
  22. //printf("NEJEDNAKI %c\n", *chars);
  23. chars++;
  24. counterf++;
  25. }
  26. /*if(*chars == **last){
  27. *last = *last - 1;
  28. chars = chars - counterl;
  29. counterl = 0;
  30. }else{
  31. chars++;
  32. counterl++;
  33. }*/
  34.  
  35. }
  36.  
  37. }
  38.  
  39. int main() {
  40. int n, q;
  41. char *s, *chars;
  42. scanf("%d%d", &n, &q);
  43. s = malloc((n+1) * sizeof(char));
  44. chars = malloc(26 * sizeof(char));
  45. scanf("%s", s);
  46. for (int i = 0; i < q; ++i) {
  47. char *first = s, *last = s+n;
  48. scanf("%s", chars);
  49. strip(&first, &last, chars);
  50. // ispisuje znakovni niz duljine last-first počevši od pokazivača first
  51. printf("%d %.*s\n", (int)(last-first), (int)(last-first), first);
  52. }
  53. free(s);
  54. free(chars);
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement