Created
October 4, 2017 17:26
-
-
Save xtotdam/77d2c34188583dd4094b64443cd5f55e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // counting lengths of chains | |
| int *lengths = (int *)calloc(N, sizeof(int)); | |
| int *zeros = (int *)calloc(N, sizeof(int)); | |
| int len, j; | |
| for (i = 0; i < N; i++) | |
| { | |
| if (atoms[i] == 0) | |
| { | |
| zeros[cnt] = i; | |
| cnt++; | |
| } | |
| } | |
| for (i = 0; i < cnt; i++) | |
| { | |
| if (i < cnt - 1) | |
| { | |
| len = zeros[i + 1] - zeros[i] - 1; | |
| for (j = zeros[i] + 1; j < zeros[i + 1]; j++) | |
| { | |
| lengths[j] = len; | |
| } | |
| } | |
| else | |
| { | |
| len = N + zeros[0] - zeros[cnt - 1] - 1; | |
| for (j = 0; j < zeros[0]; j++) | |
| { | |
| lengths[j] = len; | |
| } | |
| for (j = zeros[cnt - 1] + 1; j < N; j++) | |
| { | |
| lengths[j] = len; | |
| } | |
| } | |
| } | |
| free(lengths); | |
| free(zeros); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment