2017-10-11 17 views
-2

我有版本A和版本B的CPP代碼,版本B的,我在這些註釋標記代碼片段就像如何獲取C++代碼片段的位置?

//B specific - START 
..something here.. 
//B specific - END 

我想提取物B的特定代碼片段並將其放置在版本A合適的位置爲此,我想提取B特定代碼片段的位置。有沒有算法?

對於實施例 VersionA.cpp

// Program to print all combination of size r in an array of size n 
#include <stdio.h> 
void combinationUtil(int arr[], int data[], int start, int end, 
        int index, int r); 

// The main function that prints all combinations of size r 
// in arr[] of size n. This function mainly uses combinationUtil() 
void printCombination(int arr[], int n, int r) 
{ 
    // A temporary array to store all combination one by one 
    int data[r]; 
    int data[m]; 
    // Print all combination using temprary array 'data[]' 
    combinationUtil(arr, data, 0, n-1, 0, r); 
} 

/* arr[] ---> Input Array 
data[] ---> Temporary array to store current combination 
start & end ---> Staring and Ending indexes in arr[] 
index ---> Current index in data[] 
r ---> Size of a combination to be printed */ 
void combinationUtil(int arr[], int data[], int start, int end, 
        int index, int r) 
{ 
    // Current combination is ready to be printed, print it 
    if (index == r) 
    { 
     for (int j=0; j<r; j++) 
      printf("%d ", data[j]); 
     printf("\n"); 
     return; 
    } 

    // replace index with all possible elements. The condition 
    // "end-i+1 >= r-index" makes sure that including one element 
    // at index will make a combination with remaining elements 
    // at remaining positions 
    for (int i=start; i<=end && end-i+1 >= r-index; i++) 
    { 
     int temp; 
     data[index] = arr[i]; 
     combinationUtil(arr, data, i+1, end, index+1, r); 
    } 
} 

// Driver program to test above functions 
int main() 
{ 
    int arr[] = {1, 2, 3, 4, 5}; 
    int r = 3; 
    int n = sizeof(arr)/sizeof(arr[0]); 
    printCombination(arr, n, r); 
} 

VersionB.cpp

// Program to print all combination of size r in an array of size n 
#include <stdio.h> 
//B specific - START 
#include "...." 
#include "...." 
//B specific - END 

void combinationUtil(int arr[], int data[], int start, int end, 
        int index, int r); 

// The main function that prints all combinations of size r 
// in arr[] of size n. This function mainly uses combinationUtil() 
void printCombination(int arr[], int n, int r) 
{ 
    // A temporary array to store all combination one by one 
    int data[r]; 
    //B specific - START 
    ..something here.. 
    //B specific - END 

    // Print all combination using temprary array 'data[]' 
    combinationUtil(arr, data, 0, n-1, 0, r); 
} 

/* arr[] ---> Input Array 
    data[] ---> Temporary array to store current combination 
    start & end ---> Staring and Ending indexes in arr[] 
    index ---> Current index in data[] 
    r ---> Size of a combination to be printed */ 
void combinationUtil(int arr[], int data[], int start, int end, 
        int index, int r) 
{ 
    // Current combination is ready to be printed, print it 
    if (index == r) 
    { 
     for (int j=0; j<r; j++) 
      printf("%d ", data[j]); 
      //B specific - START 
      ..something here.. 
      //B specific - END 
     printf("\n"); 
     return; 
    } 

    // replace index with all possible elements. The condition 
    // "end-i+1 >= r-index" makes sure that including one element 
    // at index will make a combination with remaining elements 
    // at remaining positions 
    for (int i=start; i<=end && end-i+1 >= r-index; i++) 
    { 
     //B specific - START 
     ..something here.. 
     //B specific - END 
     data[index] = arr[i]; 
     combinationUtil(arr, data, i+1, end, index+1, r); 
    } 
} 

// Driver program to test above functions 
int main() 
{ 
    int arr[] = {1, 2, 3, 4, 5}; 
    int r = 3; 
    int n = sizeof(arr)/sizeof(arr[0]); 
    printCombination(arr, n, r); 
} 

輸出VersionA.cpp應該是這樣的,

// Program to print all combination of size r in an array of size n 
#include <stdio.h> 
void combinationUtil(int arr[], int data[], int start, int end, 
        int index, int r); 

// The main function that prints all combinations of size r 
// in arr[] of size n. This function mainly uses combinationUtil() 
void printCombination(int arr[], int n, int r) 
{ 
    // A temporary array to store all combination one by one 
    int data[r]; 
    //B specific - START 
    ..something here.. 
    //B specific - END 
    int data[m]; 
    // Print all combination using temprary array 'data[]' 
    combinationUtil(arr, data, 0, n-1, 0, r); 
} 

/* arr[] ---> Input Array 
data[] ---> Temporary array to store current combination 
start & end ---> Staring and Ending indexes in arr[] 
index ---> Current index in data[] 
r ---> Size of a combination to be printed */ 
void combinationUtil(int arr[], int data[], int start, int end, 
        int index, int r) 
{ 
    // Current combination is ready to be printed, print it 
    if (index == r) 
    { 
     for (int j=0; j<r; j++) 
      printf("%d ", data[j]); 
      //B specific - START 
      ..something here.. 
      //B specific - END 
     printf("\n"); 
     return; 
    } 

    // replace index with all possible elements. The condition 
    // "end-i+1 >= r-index" makes sure that including one element 
    // at index will make a combination with remaining elements 
    // at remaining positions 
    for (int i=start; i<=end && end-i+1 >= r-index; i++) 
    { 
     int temp; 
     //B specific - START 
     ..something here.. 
     //B specific - END 
     data[index] = arr[i]; 
     combinationUtil(arr, data, i+1, end, index+1, r); 
    } 
} 

// Driver program to test above functions 
int main() 
{ 
    int arr[] = {1, 2, 3, 4, 5}; 
    int r = 3; 
    int n = sizeof(arr)/sizeof(arr[0]); 
    printCombination(arr, n, r); 
} 
+0

請花些時間閱讀[幫助頁面](http://stackoverflow.com/help),尤其是名爲[「我可以問什麼問題?」]( http://stackoverflow.com/help/on-topic)和[「我應該避免問什麼類型的問題?」](http://stackoverflow.com/help/dont-ask)。還請[參觀](http://stackoverflow.com/tour)和[閱讀如何提出好問題](http://stackoverflow.com/help/how-to-ask)。最後,請學習如何創建[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。 –

+0

相關:https://stackoverflow.com/questions/14350856/can-awk-patterns-match-multiple-lines#14350923 –

+0

你可以'grep'這些片段。 – HolyBlackCat

回答

0

使用Araxis合併工具,獲取文件比較報告。使用Python腳本分析報告文件。並執行所需的合併操作