#include <bits/stdc++.h> int main() { <<<<<<< branch1 printf("Hello world!"); ======= puts("Hello World!"); >>>>>>> branch2 }
Here's an example of merging Hello World. The one on branch1 used printf, but the second programmer prefered puts. Well, one solution of that problem is to make some proper defines and make things work when different preset is on. One of the simplest ways is to change the git's mark into define, that is,
#include <bits/stdc++.h> int main() { #ifdef branch1 printf("Hello world!"); #else puts("Hello World!"); #endif }
However, sometimes git will not mark an accurate range for simplicity that replacing the marks will not result one shortest answer. The following code could be shorter if add defines differently.
#include <bits/stdc++.h> using namespace std; int main() { int a, b; <<<<<<< branch1 cin >> a >> b; ======= scanf("%d%d", &a, &b); >>>>>>> branch2 if (a < 0 || b < 0) return 1; <<<<<<< branch1 cout << a + b << endl; ======= printf("%d\n", a + b); >>>>>>> branch2 }
Your task here is to output one of the shortest possible merge answers, for some C++ code. Here're some definitions and limitations:
* There will be 1 or more conflicts in the file. The conflicts are marked with exactly the same format with the sample code. That is,
* "<<<<<<< branch1" for the beginning.
* "=======" for separating conflicts.
* ">>>>>>> branch2" for ending.
* There're 0 or more lines of code between marks.
* No "<<<<<<< branch2" or ">>>>>>> branch1" will be presented in the code.
* No nesting conflicts will be presented in the code.
* No other lines start with "<<<<<<<", "=======" or ">>>>>>>".
* The input file may not necessarily be output of git, and there's no guarantee of niceness of the marks: it may contain 'surprising' output like later samples. However, it will strictly follow the format.
#ifdef branch1 #ifdef branch2 #else #endif
* You're not supposed to insert any other directives apart from the above ones or preprocess any directives in the code.
* There's no other #if #ifdef #ifndef #endif directives in the code and no #define #undef related to "branch1" "branch2", so you don't need to treat preprocessor directives different from normal code.
* The char set of input file is all visible ASCII chars (from 33 to 126), '\n', '\t', and space(32). The line break is granted to be '\n' but not "\r\n".
* 'Shortest' means the number of lines of the code is minimum. It's not necessarily to output a shortest answer in bytes.
Input file consists of at most 4000 lines of code or git marks, with each line at most 256 byte including '\n'.It's granted that there's at least one conflict and at least one code line.
The code with minimum number of lines that will be the exact match with two branches when different defines on. If there're multiple answers, print any.The checker will try to fix some unpleasant issues, including ignore spaces at end of line and extra line breaks at end of file. However, you're recommended to output your answer in the format of samples in order to avoid Wrong Answer caused by Presentation Error.The output must be shorter than 5000 lines with each line at most 300 byte including '\n'. Otherwise, you will receive Wrong Answer verdict.
#include <bits/stdc++.h> using namespace std; int main() { int a, b; <<<<<<< branch1 cin >> a >> b; ======= scanf("%d%d", &a, &b); >>>>>>> branch2 if (a < 0 || b < 0) return 1; <<<<<<< branch1 cout << a + b << endl; ======= printf("%d\n", a + b);a >>>>>>> branch2 }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; #ifdef branch1 cin >> a >> b; if (a < 0 || b < 0) return 1; cout << a + b << endl; #else scanf("%d%d", &a, &b); if (a < 0 || b < 0) return 1; printf("%d\n", a + b);a #endif }
To show precisely how the input file formated, let's take sample 2 for example, the input file can be verified to be equal to the following string:"<<<<<<< branch1\nint main() {\n return 0;\n}\n=======\nint main() {\n}\n>>>>>>> branch2\n"and one possible output (as sample output 2) is:"int main() {\n#ifdef branch1\n return 0;\n#endif\n}\n"Note that if you're running tests on Windows, you have to aware '\r' issue when you are using getline(). The test data will not contain any '\r'.