source:
CIVL/examples/verifyThisProblems/quantifiedComp.cvl@
315d1ee
| Last change on this file since 315d1ee was 41eb9b6, checked in by , 10 years ago | |
|---|---|
|
|
| File size: 873 bytes | |
| Rev | Line | |
|---|---|---|
| [cc283ee] | 1 | /* |
| [41eb9b6] | 2 | Author: Yihao |
| [f3368e99] | 3 | |
| [41eb9b6] | 4 | Download LCP.zip from: http://fm2012.verifythis.org/challenges |
| 5 | ||
| 6 | ----------------- | |
| 7 | Problem description: | |
| [f3368e99] | 8 | |
| [cc283ee] | 9 | This is a verifyThis problem in 2012. |
| [f3368e99] | 10 | This task asks you to get the longest common prefix of |
| [cc283ee] | 11 | two subStrings. |
| 12 | ||
| [41eb9b6] | 13 | ----------------- |
| 14 | Verification task: | |
| 15 | ||
| 16 | Implement a the lcp function which takes an array, its length and two indices as input | |
| 17 | and verify that it behaves as described. | |
| [f7e5282] | 18 | |
| 19 | command: civl verify quantifiedComp.cvl | |
| 20 | ||
| 21 | result: the problem is solved | |
| [cc283ee] | 22 | */ |
| 23 | ||
| 24 | #include <civlc.cvh> | |
| 25 | #include <assert.h> | |
| 26 | ||
| 27 | $input int n=3; | |
| 28 | $input int x; | |
| 29 | $input int y; | |
| 30 | $input int X1[n]; | |
| 31 | ||
| 32 | $assume (x < n && y < n && x >=0 && y>=0); | |
| 33 | ||
| [0ae124a] | 34 | int lcp (int *arr, int n, int x, int y) { |
| [cc283ee] | 35 | int l=0; |
| [f3368e99] | 36 | |
| [cc283ee] | 37 | while (x+l<n && y+l<n && arr[x+l]==arr[y+l]) { |
| 38 | l++; | |
| 39 | } | |
| 40 | return l; | |
| 41 | } | |
| 42 | ||
| [0ae124a] | 43 | void main() { |
| [cc283ee] | 44 | int result = lcp(X1, n, x, y); |
| [f3368e99] | 45 | |
| [cc283ee] | 46 | assert($forall {int i | i>=0 && i<result} X1[x+i] == X1[y+i]); |
| 47 | } |
Note:
See TracBrowser
for help on using the repository browser.
