Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <locale.h>
- #include <string.h>
- int main(void) {
- setlocale(LC_ALL, "en_US.utf8");
- char str[10]="2134512131";
- char *ach;
- char *ach2;
- int arr[10] = {};
- int counter = 0;
- int ch = '1';
- while(NULL != strchr(str, ch)) {
- ach = strchr(str, ch);
- if(counter != 0) {
- arr[++counter] = ach-str+1+arr[--counter];
- counter++;
- } else {
- arr[counter++] = ach-str+1;
- }
- strncpy(str, ach, 10);
- ach2 = strchr(str, str[1]);
- strncpy(str, ach2, 10);
- }
- for(int i = 0; i < counter; i++)
- printf("%d ", arr[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement