1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | @author: Yihao Yan
|
|---|
| 3 |
|
|---|
| 4 | Link(LCP.zip): http://fm2012.verifythis.org/challenges
|
|---|
| 5 |
|
|---|
| 6 | This is a verifyThis problem in 2012.
|
|---|
| 7 | This task asks you to get the longest common prefix of
|
|---|
| 8 | two subStrings.
|
|---|
| 9 |
|
|---|
| 10 | Input: an integer array arr, the length of the array, and two indices x and y.
|
|---|
| 11 | */
|
|---|
| 12 |
|
|---|
| 13 | #include <civlc.cvh>
|
|---|
| 14 | #include <assert.h>
|
|---|
| 15 |
|
|---|
| 16 | $input int n=3;
|
|---|
| 17 | $input int x;
|
|---|
| 18 | $input int y;
|
|---|
| 19 | $input int X1[n];
|
|---|
| 20 |
|
|---|
| 21 | $assume (x < n && y < n && x >=0 && y>=0);
|
|---|
| 22 |
|
|---|
| 23 | int lcp(int *arr, int n, int x, int y){
|
|---|
| 24 | int l=0;
|
|---|
| 25 |
|
|---|
| 26 | while (x+l<n && y+l<n && arr[x+l]==arr[y+l]) {
|
|---|
| 27 | l++;
|
|---|
| 28 | }
|
|---|
| 29 | return l;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | void main(){
|
|---|
| 33 | int result = lcp(X1, n, x, y);
|
|---|
| 34 |
|
|---|
| 35 | assert($forall {int i | i>=0 && i<result} X1[x+i] == X1[y+i]);
|
|---|
| 36 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.