Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <locale.h>
  3. #include <string.h>
  4.  
  5. int main(void) {
  6. setlocale(LC_ALL, "en_US.utf8");
  7. char str[10]="2134512131";
  8. char *ach;
  9. char *ach2;
  10. int arr[10] = {};
  11. int counter = 0;
  12. int ch = '1';
  13. while(NULL != strchr(str, ch)) {
  14. ach = strchr(str, ch);
  15.  
  16. if(counter != 0) {
  17. arr[++counter] = ach-str+1+arr[--counter];
  18. counter++;
  19. } else {
  20. arr[counter++] = ach-str+1;
  21. }
  22.  
  23. strncpy(str, ach, 10);
  24. ach2 = strchr(str, str[1]);
  25. strncpy(str, ach2, 10);
  26. }
  27. for(int i = 0; i < counter; i++)
  28. printf("%d ", arr[i]);
  29.  
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement