HBC209996GitMerge题解

凯凯我们等你回来 算法基础篇 60 0
想要检验自己的编程水平?来试试全网最全C++题库,让您在挑战中不断进步。
Writing code with other people sometimes means wasting time — at least you will spend much time working on merging different branches and testing them for potential bugs. And sometimes, the differences marked by git is only different styles of coding!} 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. } 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

Writing code with other people sometimes means wasting time — at least you will spend much time working on merging different branches and testing them for potential bugs. And sometimes, the differences marked by git is only different styles of coding! #include 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 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 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("%dn", 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. * You can rearrange code with (only) following commands, as long as they submit to preprocessor standard (https://gcc.gnu.org/onlinedocs/gcc-2.95.3/cpp_1.html): #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. * Two defines "branch1" or "branch2" will be turned on one at a time. * Empty lines should also count as lines, and your output should be exactly matched with two files after processing. However, it's granted that input file end with single 'n' before EOF, and no extra spaces before 'n'. * 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 "rn". * 'Shortest' means the number of lines of the code is minimum. It's not necessarily to output a shortest answer in bytes.

HBC209996GitMerge题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)

标签: HBC209996GitMerge题解