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