Commit
·
b03a2fe
1
Parent(s):
6029185
fix compilation errors
Browse files
data/cpp/data/humanevalbugs.jsonl
CHANGED
@@ -53,7 +53,7 @@
|
|
53 |
{"task_id": "CPP/52", "prompt": "/*\nReturn true if all numbers in the vector l are below threshold t.\n>>> below_threshold({1, 2, 4, 10}, 100)\ntrue\n>>> below_threshold({1, 20, 4, 10}, 5)\nfalse\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nbool below_threshold(vector<int>l, int t){\n", "canonical_solution": " for (int i=0;i<l.size();i++)\n if (l[i]>=t) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (below_threshold({1, 2, 4, 10}, 100));\n assert (not(below_threshold({1, 20, 4, 10}, 5)));\n assert (below_threshold({1, 20, 4, 10}, 21));\n assert (below_threshold({1, 20, 4, 10}, 22));\n assert (below_threshold({1, 8, 4, 10}, 11));\n assert (not(below_threshold({1, 8, 4, 10}, 10)));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool below_threshold(vector<int>l, int t){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (below_threshold({1, 2, 4, 10}, 100));\n assert (not(below_threshold({1, 20, 4, 10}, 5)));\n}\n", "buggy_solution": " for (int i=0;i<l.size();i++)\n if (l[i]>=t) return true;\n return false;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "below_threshold"}
|
54 |
{"task_id": "CPP/53", "prompt": "/*\nAdd two numbers x and y\n>>> add(2, 3)\n5\n>>> add(5, 7)\n12\n*/\n#include<stdio.h>\n#include<stdlib.h>\nusing namespace std;\nint add(int x,int y){\n", "canonical_solution": " return x+y;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (add(0, 1) == 1);\n assert (add(1, 0) == 1);\n assert (add(2, 3) == 5);\n assert (add(5, 7) == 12);\n assert (add(7, 5) == 12);\n for (int i=0;i<100;i+=1)\n {\n int x=rand()%1000;\n int y=rand()%1000;\n assert (add(x, y) == x + y);\n }\n}\n", "declaration": "#include<stdio.h>\n#include<stdlib.h>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\nint add(int x,int y){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (add(2, 3) == 5);\n assert (add(5, 7) == 12);\n}\n", "buggy_solution": " return x+y+y+x;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "add"}
|
55 |
{"task_id": "CPP/54", "prompt": "/*\nCheck if two words have the same characters.\n>>> same_chars(\"eabcdzzzz\", \"dddzzzzzzzddeddabc\")\ntrue\n>>> same_chars(\"abcd\", \"dddddddabc\")\ntrue\n>>> same_chars(\"dddddddabc\", \"abcd\")\ntrue\n>>> same_chars(\"eabcd\", \"dddddddabc\")\nfalse\n>>> same_chars(\"abcd\", \"dddddddabce\")\nfalse\n>>> same_chars(\"eabcdzzzz\", \"dddzzzzzzzddddabc\")\nfalse\n*/\n#include<stdio.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\nbool same_chars(string s0,string s1){\n", "canonical_solution": " for (int i=0;i<s0.length();i++)\n if (find(s1.begin(),s1.end(),s0[i])==s1.end())\n return false;\n for (int i=0;i<s1.length();i++)\n if (find(s0.begin(),s0.end(),s1[i])==s0.end())\n return false;\n return true; \n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (same_chars(\"eabcdzzzz\", \"dddzzzzzzzddeddabc\") == true);\n assert (same_chars(\"abcd\", \"dddddddabc\") == true);\n assert (same_chars(\"dddddddabc\", \"abcd\") == true);\n assert (same_chars(\"eabcd\", \"dddddddabc\") == false);\n assert (same_chars(\"abcd\", \"dddddddabcf\") == false);\n assert (same_chars(\"eabcdzzzz\", \"dddzzzzzzzddddabc\") == false);\n assert (same_chars(\"aabb\", \"aaccc\") == false);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool same_chars(string s0,string s1){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (same_chars(\"eabcdzzzz\", \"dddzzzzzzzddeddabc\") == true);\n assert (same_chars(\"abcd\", \"dddddddabc\") == true);\n assert (same_chars(\"dddddddabc\", \"abcd\") == true);\n assert (same_chars(\"eabcd\", \"dddddddabc\") == false);\n assert (same_chars(\"abcd\", \"dddddddabcf\") == false);\n assert (same_chars(\"eabcdzzzz\", \"dddzzzzzzzddddabc\") == false);\n}\n", "buggy_solution": " for (int i=0;i<s0.length();i++)\n if (find(s1.begin(),s1.end(),s0[i])==s1.end())\n return false;\n return true; \n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "same_chars"}
|
56 |
-
{"task_id": "CPP/55", "prompt": "/*\nReturn n-th Fibonacci number.\n>>> fib(10)\n55\n>>> fib(1)\n1\n>>> fib(8)\n21\n*/\n#include<stdio.h>\nusing namespace std;\nint fib(int n){\n", "canonical_solution": " int f[1000];\n f[0]=0;f[1]=1;\n for (int i=2;i<=n; i++)\n f[i]=f[i-1]+f[i-2];\n return f[n];\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (fib(10) == 55);\n assert (fib(1) == 1);\n assert (fib(8) == 21);\n assert (fib(11) == 89);\n assert (fib(12) == 144);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nint fib(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (fib(10) == 55);\n assert (fib(1) == 1);\n assert (fib(8) == 21);\n}\n", "buggy_solution": " int f[1000];\n f[0]=0;f[1]=1;f[2]=2
|
57 |
{"task_id": "CPP/56", "prompt": "/*\nbrackets is a string of '<' and '>'.\nreturn true if every opening bracket has a corresponding closing bracket.\n\n>>> correct_bracketing(\"<\")\nfalse\n>>> correct_bracketing(\"<>\")\ntrue\n>>> correct_bracketing(\"<<><>>\")\ntrue\n>>> correct_bracketing(\"><<>\")\nfalse\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool correct_bracketing(string brackets){\n", "canonical_solution": " int level=0;\n for (int i=0;i<brackets.length();i++)\n {\n if (brackets[i]=='<') level+=1;\n if (brackets[i]=='>') level-=1;\n if (level<0) return false;\n }\n if (level!=0) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (correct_bracketing(\"<>\"));\n assert (correct_bracketing(\"<<><>>\"));\n assert (correct_bracketing(\"<><><<><>><>\"));\n assert (correct_bracketing(\"<><><<<><><>><>><<><><<>>>\"));\n assert (not (correct_bracketing(\"<<<><>>>>\")));\n assert (not (correct_bracketing(\"><<>\")));\n assert (not (correct_bracketing(\"<\")));\n assert (not (correct_bracketing(\"<<<<\")));\n assert (not (correct_bracketing(\">\")));\n assert (not (correct_bracketing(\"<<>\")));\n assert (not (correct_bracketing(\"<><><<><>><>><<>\")));\n assert (not (correct_bracketing(\"<><><<><>><>>><>\")));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool correct_bracketing(string brackets){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (correct_bracketing(\"<>\"));\n assert (correct_bracketing(\"<<><>>\"));\n assert (not (correct_bracketing(\"><<>\")));\n assert (not (correct_bracketing(\"<\")));\n}\n", "buggy_solution": " int level=0;\n for (int i=0;i<brackets.length();i++)\n {\n if (brackets[i]=='>') level+=1;\n if (brackets[i]=='<') level-=1;\n if (level<0) return false;\n }\n if (level!=0) return false;\n return true;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "correct_bracketing"}
|
58 |
{"task_id": "CPP/57", "prompt": "/*\nReturn true is vector elements are monotonically increasing or decreasing.\n>>> monotonic({1, 2, 4, 20})\ntrue\n>>> monotonic({1, 20, 4, 10})\nfalse\n>>> monotonic({4, 1, 0, -10})\ntrue\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nbool monotonic(vector<float> l){\n", "canonical_solution": " int incr,decr;\n incr=0;decr=0;\n for (int i=1;i<l.size();i++)\n {\n if (l[i]>l[i-1]) incr=1;\n if (l[i]<l[i-1]) decr=1;\n }\n if (incr+decr==2) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (monotonic({1, 2, 4, 10}) == true);\n assert (monotonic({1, 2, 4, 20}) == true);\n assert (monotonic({1, 20, 4, 10}) == false);\n assert (monotonic({4, 1, 0, -10}) == true);\n assert (monotonic({4, 1, 1, 0}) == true);\n assert (monotonic({1, 2, 3, 2, 5, 60}) == false);\n assert (monotonic({1, 2, 3, 4, 5, 60}) == true);\n assert (monotonic({9, 9, 9, 9}) == true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool monotonic(vector<float> l){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (monotonic({1, 2, 4, 10}) == true);\n assert (monotonic({1, 20, 4, 10}) == false);\n assert (monotonic({4, 1, 0, -10}) == true);\n}\n", "buggy_solution": " int incr,decr;\n incr=0;decr=0;\n for (int i=1;i<l.size();i++)\n {\n if (l[i]>l[i-1]) incr=1;\n if (l[i]<l[i-1]) decr=1;\n }\n if (incr+decr==2) return true;\n return false;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "monotonic"}
|
59 |
{"task_id": "CPP/58", "prompt": "/*\nReturn sorted unique common elements for two vectors.\n>>> common({1, 4, 3, 34, 653, 2, 5}, {5, 7, 1, 5, 9, 653, 121})\n{1, 5, 653}\n>>> common({5, 3, 2, 8}, {3, 2})\n{2, 3}\n\n*/\n#include<stdio.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\nvector<int> common(vector<int> l1,vector<int> l2){\n", "canonical_solution": " vector<int> out={};\n for (int i=0;i<l1.size();i++)\n if (find(out.begin(),out.end(),l1[i])==out.end())\n if (find(l2.begin(),l2.end(),l1[i])!=l2.end())\n out.push_back(l1[i]);\n sort(out.begin(),out.end());\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(common({1, 4, 3, 34, 653, 2, 5}, {5, 7, 1, 5, 9, 653, 121}) , {1, 5, 653}));\n assert (issame(common({5, 3, 2, 8}, {3, 2}) , {2, 3}));\n assert (issame(common({4, 3, 2, 8}, {3, 2, 4}) , {2, 3, 4}));\n assert (issame(common({4, 3, 2, 8}, {}) , {}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nvector<int> common(vector<int> l1,vector<int> l2){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(common({1, 4, 3, 34, 653, 2, 5}, {5, 7, 1, 5, 9, 653, 121}) , {1, 5, 653}));\n assert (issame(common({5, 3, 2, 8}, {3, 2}) , {2, 3}));\n}\n", "buggy_solution": " vector<int> out={};\n for (int i=0;i<l1.size();i++)\n if (find(out.begin(),out.end(),l1[i])==out.end())\n out.push_back(l1[i]);\n sort(out.begin(),out.end());\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "common"}
|
@@ -138,7 +138,7 @@
|
|
138 |
{"task_id": "CPP/137", "prompt": "/*\nCreate a function that takes integers, floats, or strings representing\nreal numbers, and returns the larger variable in its given variable type.\nReturn \"None\" if the values are equal.\nNote: If a real number is represented as a string, the floating point might be . or ,\n\ncompare_one(1, 2.5) \u279e 2.5\ncompare_one(1, \"2,3\") \u279e \"2,3\"\ncompare_one(\"5,1\", \"6\") \u279e \"6\"\ncompare_one(\"1\", 1) \u279e \"None\"\n*/\n#include<stdio.h>\n#include<string>\n#include<algorithm>\n#include<boost/any.hpp>\nusing namespace std;\nboost::any compare_one(boost::any a,boost::any b){\n", "canonical_solution": " double numa,numb;\n boost::any out;\n \n if (a.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(a);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1);\n numa=atof(s.c_str());\n \n }\n else \n {\n if (a.type()==typeid(int)) numa=boost::any_cast<int>(a);\n if (a.type()==typeid(double)) numa=boost::any_cast<double>(a);\n }\n if (b.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(b);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1);\n numb=atof(s.c_str());\n }\n else \n {\n if (b.type()==typeid(int)) numb=boost::any_cast<int>(b);\n if (b.type()==typeid(double)) numb=boost::any_cast<double>(b);\n }\n\n if (numa==numb) return string(\"None\");\n if (numa<numb) return b;\n if (numa>numb) return a;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (boost::any_cast<int>(compare_one(1, 2)) == 2);\n assert (boost::any_cast<double>(compare_one(1, 2.5))== 2.5);\n assert (boost::any_cast<int>(compare_one(2, 3)) == 3);\n assert (boost::any_cast<int>(compare_one(5, 6)) == 6);\n assert (boost::any_cast<string>(compare_one(1, string(\"2,3\")))== \"2,3\");\n assert (boost::any_cast<string>(compare_one(string(\"5,1\"), string(\"6\"))) == \"6\");\n assert (boost::any_cast<string>(compare_one(string(\"1\"), string(\"2\"))) == \"2\");\n assert (boost::any_cast<string>(compare_one(string(\"1\"), 1)) == \"None\");\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\n#include<boost/any.hpp>\nusing namespace std;\n#include<stdlib.h>\nboost::any compare_one(boost::any a,boost::any b){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (boost::any_cast<double>(compare_one(1, 2.5))== 2.5);\n assert (boost::any_cast<string>(compare_one(1, string(\"2,3\")))== \"2,3\");\n assert (boost::any_cast<string>(compare_one(string(\"5,1\"), string(\"6\"))) == \"6\");\n assert (boost::any_cast<string>(compare_one(string(\"1\"), 1)) == \"None\");\n}\n", "buggy_solution": " double numa,numb;\n boost::any out;\n \n if (a.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(a);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1);\n numa=atof(s.c_str());\n \n }\n else \n {\n if (a.type()==typeid(int)) numa=boost::any_cast<int>(a);\n if (a.type()==typeid(double)) numa=boost::any_cast<double>(a);\n }\n if (b.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(b);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1)+',';\n numb=atof(s.c_str());\n }\n else \n {\n if (b.type()==typeid(int)) numb=boost::any_cast<int>(b);\n if (b.type()==typeid(double)) numb=boost::any_cast<double>(b);\n }\n\n if (numa==numb) return string(\"None\");\n if (numa<numb) return b;\n if (numa>numb) return a;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "compare_one"}
|
139 |
{"task_id": "CPP/138", "prompt": "/*\nEvaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\nExample\nis_equal_to_sum_even(4) == false\nis_equal_to_sum_even(6) == false\nis_equal_to_sum_even(8) == true\n*/\n#include<stdio.h>\nusing namespace std;\nbool is_equal_to_sum_even(int n){\n", "canonical_solution": " if (n%2==0 and n>=8) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_equal_to_sum_even(4) == false);\n assert (is_equal_to_sum_even(6) == false);\n assert (is_equal_to_sum_even(8) == true);\n assert (is_equal_to_sum_even(10) == true);\n assert (is_equal_to_sum_even(11) == false);\n assert (is_equal_to_sum_even(12) == true);\n assert (is_equal_to_sum_even(13) == false);\n assert (is_equal_to_sum_even(16) == true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool is_equal_to_sum_even(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_equal_to_sum_even(4) == false);\n assert (is_equal_to_sum_even(6) == false);\n assert (is_equal_to_sum_even(8) == true);\n}\n", "buggy_solution": " if (n%2==0 and n>=8 and n <=8) return true;\n return false;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "is_equal_to_sum_even"}
|
140 |
{"task_id": "CPP/139", "prompt": "/*\nThe Brazilian factorial is defined as:\nbrazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\nwhere n > 0\n\nFor example:\n>>> special_factorial(4)\n288\n\nThe function will receive an integer as input and should return the special\nfactorial of this integer.\n*/\n#include<stdio.h>\nusing namespace std;\nlong long special_factorial(int n){\n", "canonical_solution": " long long fact=1,bfact=1;\n for (int i=1;i<=n;i++)\n {\n fact=fact*i;\n bfact=bfact*fact;\n }\n return bfact;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (special_factorial(4) == 288);\n assert (special_factorial(5) == 34560);\n assert (special_factorial(7) == 125411328000);\n assert (special_factorial(1) == 1);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nlong long special_factorial(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (special_factorial(4) == 288);\n}\n", "buggy_solution": " long long fact=1,bfact=1;\n for (int i=1;i<=n;i++)\n {\n i=i*n;\n fact=fact*i;\n bfact=bfact*fact;\n }\n return bfact;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "special_factorial"}
|
141 |
-
{"task_id": "CPP/140", "prompt": "/*\nGiven a string text, replace all spaces in it with underscores, \nand if a string has more than 2 consecutive spaces, \nthen replace all consecutive spaces with - \n\nfix_spaces(\"Example\") == \"Example\"\nfix_spaces(\"Example 1\") == \"Example_1\"\nfix_spaces(\" Example 2\") == \"_Example_2\"\nfix_spaces(\" Example 3\") == \"_Example-3\"\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring fix_spaces(string text){\n", "canonical_solution": " string out=\"\";\n int spacelen=0;\n for (int i=0;i<text.length();i++)\n if (text[i]==' ') spacelen+=1;\n else\n {\n if (spacelen==1) out=out+'_';\n if (spacelen==2) out=out+\"__\";\n if (spacelen>2) out=out+'-';\n spacelen=0;\n out=out+text[i];\n }\n if (spacelen==1) out=out+'_';\n if (spacelen==2) out=out+\"__\";\n if (spacelen>2) out=out+'-';\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (fix_spaces(\"Example\") == \"Example\");\n assert (fix_spaces(\"Mudasir Hanif \") == \"Mudasir_Hanif_\");\n assert (fix_spaces(\"Yellow Yellow Dirty Fellow\") == \"Yellow_Yellow__Dirty__Fellow\");\n assert (fix_spaces(\"Exa mple\") == \"Exa-mple\");\n assert (fix_spaces(\" Exa 1 2 2 mple\") == \"-Exa_1_2_2_mple\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring fix_spaces(string text){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (fix_spaces(\"Example\") == \"Example\");\n assert (fix_spaces(\"Example 1\") == \"Example_1\");\n assert (fix_spaces(\" Example 2\") == \"_Example_2\");\n assert (fix_spaces(\" Example 3\") == \"_Example-3\");\n}\n", "buggy_solution": " string out=\"\";\n int spacelen=0;\n for (int i=0;i<text.length();i++)\n if (text[i]=='
|
142 |
{"task_id": "CPP/141", "prompt": "/*\nCreate a function which takes a string representing a file's name, and returns\n\"Yes\" if the the file's name is valid, and returns \"No\" otherwise.\nA file's name is considered to be valid if and only if all the following conditions \nare met:\n- There should not be more than three digits ('0'-'9') in the file's name.\n- The file's name contains exactly one dot \".\"\n- The substring before the dot should not be empty, and it starts with a letter from \nthe latin alphapet ('a'-'z' and 'A'-'Z').\n- The substring after the dot should be one of these: {'txt\", \"exe\", \"dll\"}\nExamples:\nfile_name_check(\"example.txt\") => \"Yes\"\nfile_name_check(\"1example.dll\") => \"No\" // (the name should start with a latin alphapet letter)\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring file_name_check(string file_name){\n", "canonical_solution": " int numdigit=0,numdot=0;\n if (file_name.length()<5) return \"No\";\n char w=file_name[0];\n if (w<65 or (w>90 and w<97) or w>122) return \"No\";\n string last=file_name.substr(file_name.length()-4,4);\n if (last!=\".txt\" and last!=\".exe\" and last!=\".dll\") return \"No\";\n for (int i=0;i<file_name.length();i++)\n {\n if (file_name[i]>=48 and file_name[i]<=57) numdigit+=1;\n if (file_name[i]=='.') numdot+=1;\n }\n if (numdigit>3 or numdot!=1) return \"No\";\n return \"Yes\"; \n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (file_name_check(\"example.txt\") == \"Yes\");\n assert (file_name_check(\"1example.dll\") == \"No\");\n assert (file_name_check(\"s1sdf3.asd\") == \"No\");\n assert (file_name_check(\"K.dll\") == \"Yes\");\n assert (file_name_check(\"MY16FILE3.exe\") == \"Yes\");\n assert (file_name_check(\"His12FILE94.exe\") == \"No\");\n assert (file_name_check(\"_Y.txt\") == \"No\");\n assert (file_name_check(\"?aREYA.exe\") == \"No\");\n assert (file_name_check(\"/this_is_valid.dll\") == \"No\");\n assert (file_name_check(\"this_is_valid.wow\") == \"No\");\n assert (file_name_check(\"this_is_valid.txt\") == \"Yes\");\n assert (file_name_check(\"this_is_valid.txtexe\") == \"No\");\n assert (file_name_check(\"#this2_i4s_5valid.ten\") == \"No\");\n assert (file_name_check(\"@this1_is6_valid.exe\") == \"No\");\n assert (file_name_check(\"this_is_12valid.6exe4.txt\") == \"No\");\n assert (file_name_check(\"all.exe.txt\") == \"No\");\n assert (file_name_check(\"I563_No.exe\") == \"Yes\");\n assert (file_name_check(\"Is3youfault.txt\") == \"Yes\");\n assert (file_name_check(\"no_one#knows.dll\") == \"Yes\");\n assert (file_name_check(\"1I563_Yes3.exe\") == \"No\");\n assert (file_name_check(\"I563_Yes3.txtt\") == \"No\");\n assert (file_name_check(\"final..txt\") == \"No\");\n assert (file_name_check(\"final132\") == \"No\");\n assert (file_name_check(\"_f4indsartal132.\") == \"No\");\n assert (file_name_check(\".txt\") == \"No\");\n assert (file_name_check(\"s.\") == \"No\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<math.h>\n#include<stdlib.h>\nstring file_name_check(string file_name){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (file_name_check(\"example.txt\") == \"Yes\");\n assert (file_name_check(\"1example.dll\") == \"No\");\n}\n", "buggy_solution": " int numdigit=0,numdot=0;\n if (file_name.length()<5) return \"No\";\n char w=file_name[0];\n if (w<65 or (w>90 and w<97) or w>122) return \"No\";\n string last=file_name.substr(file_name.length()-4,4);\n if (last!=\".txt\" and last!=\".exe\" and last!=\".dll\") return \"No\";\n for (int i=0;i<file_name.length();i++)\n {\n if (file_name[i]>=48 and file_name[i]<=57) numdigit+=1;\n }\n if (numdigit>3 or numdot!=1) return \"No\";\n return \"Yes\"; \n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "file_name_check"}
|
143 |
{"task_id": "CPP/142", "prompt": "/*\n\"\nThis function will take a vector of integers. For all entries in the vector, the function shall square the integer entry if its index is a \nmultiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not \nchange the entries in the vector whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. \n\nExamples:\nFor lst = {1,2,3} the output should be 6\nFor lst = {} the output should be 0\nFor lst = {-1,-5,2,-1,-5} the output should be -126\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nint sum_squares(vector<int> lst){\n", "canonical_solution": " int sum=0;\n for (int i=0;i<lst.size();i++)\n if (i%3==0) sum+=lst[i]*lst[i];\n else if (i%4==0) sum+=lst[i]*lst[i]*lst[i];\n else sum+=lst[i];\n return sum;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (sum_squares({1,2,3}) == 6);\n assert (sum_squares({1,4,9}) == 14);\n assert (sum_squares({}) == 0);\n assert (sum_squares({1,1,1,1,1,1,1,1,1}) == 9);\n assert (sum_squares({-1,-1,-1,-1,-1,-1,-1,-1,-1}) == -3);\n assert (sum_squares({0}) == 0);\n assert (sum_squares({-1,-5,2,-1,-5}) == -126);\n assert (sum_squares({-56,-99,1,0,-2}) == 3030);\n assert (sum_squares({-1,0,0,0,0,0,0,0,-1}) == 0);\n assert (sum_squares({-16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37}) == -14196);\n assert (sum_squares({-1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16, 4, 10}) == -1448);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint sum_squares(vector<int> lst){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (sum_squares({1,2,3}) == 6);\n assert (sum_squares({}) == 0);\n assert (sum_squares({-1,-5,2,-1,-5}) == -126);\n}\n", "buggy_solution": " int sum=0;\n for (int i=0;i<lst.size();i++)\n if (i%3==0) sum+=lst[i]*lst[i];\n else sum+=lst[i];\n return sum;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sum_squares"}
|
144 |
{"task_id": "CPP/143", "prompt": "/*\nYou are given a string representing a sentence,\nthe sentence contains some words separated by a space,\nand you have to return a string that contains the words from the original sentence,\nwhose lengths are prime numbers,\nthe order of the words in the new string should be the same as the original one.\n\nExample 1:\n Input: sentence = \"This is a test\"\n Output: \"is\"\n\nExample 2:\n Input: sentence = \"lets go for swimming\"\n Output: \"go for\"\n\nConstraints:\n * 1 <= len(sentence) <= 100\n * sentence contains only letters\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring words_in_sentence(string sentence){\n", "canonical_solution": " string out=\"\";\n string current=\"\";\n sentence=sentence+' ';\n\n for (int i=0;i<sentence.size();i++)\n if (sentence[i]!=' ') current=current+sentence[i];\n else\n {\n bool isp=true;\n int l=current.length();\n if (l<2) isp=false;\n for (int j=2;j*j<=l;j++)\n if (l%j==0) isp=false;\n if (isp) out=out+current+' ';\n current=\"\"; \n }\n if (out.length()>0)\n out.pop_back();\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (words_in_sentence(\"This is a test\") == \"is\");\n assert (words_in_sentence(\"lets go for swimming\") == \"go for\");\n assert (words_in_sentence(\"there is no place available here\") == \"there is no place\");\n assert (words_in_sentence(\"Hi I am Hussein\") == \"Hi am Hussein\");\n assert (words_in_sentence(\"go for it\") == \"go for it\");\n assert (words_in_sentence(\"here\") == \"\");\n assert (words_in_sentence(\"here is\") == \"is\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring words_in_sentence(string sentence){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (words_in_sentence(\"This is a test\") == \"is\");\n assert (words_in_sentence(\"lets go for swimming\") == \"go for\");\n}\n", "buggy_solution": " string out=\"\";\n string current=\"\";\n sentence=sentence+' ';\n\n for (int i=0;i<sentence.size();i++)\n if (sentence[i]!=' ') current=current+sentence[i];\n else\n {\n bool isp=true;\n int l=current.length();\n if (l<2) isp=false;\n for (int j=2;j*j<=l;j++)\n if (l%j==0) isp=false;\n if (isp) out=out+current+' ';\n current=\"\"; \n }\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "words_in_sentence"}
|
@@ -155,7 +155,7 @@
|
|
155 |
{"task_id": "CPP/154", "prompt": "/*\nYou are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\ncycpattern_check(\"abcd\",\"abd\") => false\ncycpattern_check(\"hello\",\"ell\") => true\ncycpattern_check(\"whassup\",\"psus\") => false\ncycpattern_check(\"abab\",\"baa\") => true\ncycpattern_check(\"efef\",\"eeff\") => false\ncycpattern_check(\"himenss\",'simen\") => true\n\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool cycpattern_check(string a,string b){\n", "canonical_solution": " for (int i=0;i<b.size();i++)\n {\n string rotate=b.substr(i)+b.substr(0,i);\n if (a.find(rotate)!=string::npos) return true;\n }\n return false;\n\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (cycpattern_check(\"xyzw\",\"xyw\") == false );\n assert (cycpattern_check(\"yello\",\"ell\") == true );\n assert (cycpattern_check(\"whattup\",\"ptut\") == false );\n assert (cycpattern_check(\"efef\",\"fee\") == true );\n assert (cycpattern_check(\"abab\",\"aabb\") == false );\n assert (cycpattern_check(\"winemtt\",\"tinem\") == true );\n}\n", "declaration": "#include<stdio.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nbool cycpattern_check(string a,string b){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (cycpattern_check(\"abcd\",\"abd\") == false );\n assert (cycpattern_check(\"hello\",\"ell\") == true );\n assert (cycpattern_check(\"whassup\",\"psus\") == false );\n assert (cycpattern_check(\"abab\",\"baa\") == true );\n assert (cycpattern_check(\"efef\",\"eeff\") == false );\n assert (cycpattern_check(\"himenss\",\"simen\") == true );\n}\n", "buggy_solution": " for (int i=0;i<b.size();i++)\n {\n string rotate=b.substr(i)+b.substr(0);\n if (a.find(rotate)!=string::npos) return true;\n }\n return false;\n\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "cycpattern_check"}
|
156 |
{"task_id": "CPP/155", "prompt": "/*\nGiven an integer. return a vector that has the number of even and odd digits respectively.\n\n Example:\n even_odd_count(-12) ==> {1, 1}\n even_odd_count(123) ==> {1, 2}\n*/\n#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<vector>\nusing namespace std;\nvector<int> even_odd_count(int num){\n", "canonical_solution": " string w=to_string(abs(num));\n int n1=0,n2=0;\n for (int i=0;i<w.length();i++)\n if (w[i]%2==1) n1+=1;\n else n2+=1;\n return {n2,n1};\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(even_odd_count(7) , {0, 1}));\n assert (issame(even_odd_count(-78) , {1, 1}));\n assert (issame(even_odd_count(3452) , {2, 2}));\n assert (issame(even_odd_count(346211) , {3, 3}));\n assert (issame(even_odd_count(-345821) , {3, 3}));\n assert (issame(even_odd_count(-2) , {1, 0}));\n assert (issame(even_odd_count(-45347) , {2, 3}));\n assert (issame(even_odd_count(0) , {1, 0}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nvector<int> even_odd_count(int num){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(even_odd_count(-12) , {1, 1}));\n assert (issame(even_odd_count(123) , {1, 2}));\n}\n", "buggy_solution": " string w=to_string(abs(num));\n int n1=0,n2=0;\n for (int i=0;i<w.length();i++)\n if (w[i]%2==1) n1+=1;\n return {n2,n1};\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "even_odd_count"}
|
157 |
{"task_id": "CPP/156", "prompt": "/*\nGiven a positive integer, obtain its roman numeral equivalent as a string,\nand return it in lowercase.\nRestrictions: 1 <= num <= 1000\n\nExamples:\n>>> int_to_mini_roman(19) == \"xix\"\n>>> int_to_mini_roman(152) == \"clii\"\n>>> int_to_mini_roman(426) == \"cdxxvi\"\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nstring int_to_mini_romank(int number){\n", "canonical_solution": " string current=\"\";\n vector<string> rep={\"m\",\"cm\",\"d\",\"cd\",\"c\",\"xc\",\"l\",\"xl\",\"x\",\"ix\",\"v\",\"iv\",\"i\"};\n vector<int> num={1000,900,500,400,100,90,50,40,10,9,5,4,1};\n int pos=0;\n while(number>0)\n {\n while (number>=num[pos])\n {\n current=current+rep[pos];\n number-=num[pos];\n }\n if (number>0) pos+=1;\n }\n return current;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (int_to_mini_romank(19) == \"xix\");\n assert (int_to_mini_romank(152) == \"clii\");\n assert (int_to_mini_romank(251) == \"ccli\");\n assert (int_to_mini_romank(426) == \"cdxxvi\");\n assert (int_to_mini_romank(500) == \"d\");\n assert (int_to_mini_romank(1) == \"i\");\n assert (int_to_mini_romank(4) == \"iv\");\n assert (int_to_mini_romank(43) == \"xliii\");\n assert (int_to_mini_romank(90) == \"xc\");\n assert (int_to_mini_romank(94) == \"xciv\");\n assert (int_to_mini_romank(532) == \"dxxxii\");\n assert (int_to_mini_romank(900) == \"cm\");\n assert (int_to_mini_romank(994) == \"cmxciv\");\n assert (int_to_mini_romank(1000) == \"m\");\n}\n", "declaration": "#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring int_to_mini_romank(int number){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (int_to_mini_romank(19) == \"xix\");\n assert (int_to_mini_romank(152) == \"clii\");\n assert (int_to_mini_romank(426) == \"cdxxvi\");\n}\n", "buggy_solution": " string current=\"\";\n vector<string> rep={\"m\",\"cm\",\"d\",\"cd\",\"c\",\"xc\",\"l\",\"xl\",\"x\",\"ix\",\"v\",\"iv\",\"i\"};\n vector<int> num={1000,900,500,400,100,90,50,40,10,9,5,4,1};\n int pos=0;\n while(number>0)\n {\n while (number>=num[pos])\n {\n current=current+rep[pos];\n }\n if (number>0) pos+=1;\n }\n return current;\n}\n", "bug_type": "missing logic", "failure_symptoms": "infinite loop", "entry_point": "int_to_mini_roman"}
|
158 |
-
{"task_id": "CPP/157", "prompt": "/*\nGiven the lengths of the three sides of a triangle. Return true if the three\nsides form a right-angled triangle, false otherwise.\nA right-angled triangle is a triangle in which one angle is right angle or \n90 degree.\nExample:\nright_angle_triangle(3, 4, 5) == true\nright_angle_triangle(1, 2, 3) == false\n*/\n#include<stdio.h>\n#include<math.h>\nusing namespace std;\nbool right_angle_triangle(float a,float b,float c){\n", "canonical_solution": " if (abs(a*a+b*b-c*c)<1e-4 or abs(a*a+c*c-b*b)<1e-4 or abs(b*b+c*c-a*a)<1e-4) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (right_angle_triangle(3, 4, 5) == true);\n assert (right_angle_triangle(1, 2, 3) == false);\n assert (right_angle_triangle(10, 6, 8) == true);\n assert (right_angle_triangle(2, 2, 2) == false);\n assert (right_angle_triangle(7, 24, 25) == true);\n assert (right_angle_triangle(10, 5, 7) == false);\n assert (right_angle_triangle(5, 12, 13) == true);\n assert (right_angle_triangle(15, 8, 17) == true);\n assert (right_angle_triangle(48, 55, 73) == true);\n assert (right_angle_triangle(1, 1, 1) == false);\n assert (right_angle_triangle(2, 2, 10) == false);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool right_angle_triangle(float a,float b,float c){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (right_angle_triangle(3, 4, 5) == true);\n assert (right_angle_triangle(1, 2, 3) == false);\n}\n", "buggy_solution": " if (abs(a*a+b*b-c*c)<1e-4 return true;\n return false;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "right_angle_triangle"}
|
159 |
{"task_id": "CPP/158", "prompt": "/*\nWrite a function that accepts a vector of strings.\nThe vector contains different words. Return the word with maximum number\nof unique characters. If multiple strings have maximum number of unique\ncharacters, return the one which comes first in lexicographical order.\n\nfind_max({\"name\", \"of\", 'string\"}) == 'string\"\nfind_max({\"name\", \"enam\", \"game\"}) == \"enam\"\nfind_max({\"aaaaaaa\", \"bb\" ,\"cc\"}) == \"aaaaaaa\"\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\nstring find_max(vector<string> words){\n", "canonical_solution": " string max=\"\";\n int maxu=0;\n for (int i=0;i<words.size();i++)\n {\n string unique=\"\";\n for (int j=0;j<words[i].length();j++)\n if (find(unique.begin(),unique.end(),words[i][j])==unique.end())\n unique=unique+words[i][j];\n if (unique.length()>maxu or (unique.length()==maxu and words[i]<max))\n {\n max=words[i];\n maxu=unique.length();\n }\n }\n return max;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert ((find_max({\"name\", \"of\", \"string\"}) == \"string\"));\n assert ((find_max({\"name\", \"enam\", \"game\"}) == \"enam\"));\n assert ((find_max({\"aaaaaaa\", \"bb\", \"cc\"}) == \"aaaaaaa\"));\n assert ((find_max({\"abc\", \"cba\"}) == \"abc\"));\n assert ((find_max({\"play\", \"this\", \"game\", \"of\",\"footbott\"}) == \"footbott\"));\n assert ((find_max({\"we\", \"are\", \"gonna\", \"rock\"}) == \"gonna\"));\n assert ((find_max({\"we\", \"are\", \"a\", \"mad\", \"nation\"}) == \"nation\"));\n assert ((find_max({\"this\", \"is\", \"a\", \"prrk\"}) == \"this\"));\n assert ((find_max({\"b\"}) == \"b\"));\n assert ((find_max({\"play\", \"play\", \"play\"}) == \"play\"));\n}\n", "declaration": "#include<stdio.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<math.h>\n#include<stdlib.h>\nstring find_max(vector<string> words){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert ((find_max({\"name\", \"of\", \"string\"}) == \"string\"));\n assert ((find_max({\"name\", \"enam\", \"game\"}) == \"enam\"));\n assert ((find_max({\"aaaaaaa\", \"bb\", \"cc\"}) == \"aaaaaaa\"));\n}\n", "buggy_solution": " string max=\"\";\n int maxu=0;\n for (int i=0;i<words.size();i++)\n {\n string unique=\"\";\n for (int j=0;j<words[i].length();j++)\n if (find(unique.begin(),unique.end(),words[i][j])==unique.end())\n unique=unique+words[i][j];\n if (unique.length()>maxu or unique.length()==maxu)\n {\n max=words[i];\n maxu=unique.length();\n }\n }\n return max;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "find_max"}
|
160 |
{"task_id": "CPP/159", "prompt": "/*\nYou\"re a hungry rabbit, and you already have eaten a certain number of carrots,\nbut now you need to eat more carrots to complete the day's meals.\nyou should return a vector of { total number of eaten carrots after your meals,\n the number of carrots left after your meals }\nif there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.\n\nExample:\n* eat(5, 6, 10) -> {11, 4}\n* eat(4, 8, 9) -> {12, 1}\n* eat(1, 10, 10) -> {11, 0}\n* eat(2, 11, 5) -> {7, 0}\n\nVariables:\n@number : integer\n the number of carrots that you have eaten.\n@need : integer\n the number of carrots that you need to eat.\n@remaining : integer\n the number of remaining carrots thet exist in stock\n\nConstrain:\n* 0 <= number <= 1000\n* 0 <= need <= 1000\n* 0 <= remaining <= 1000\n\nHave fun :)\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nvector<int> eat(int number,int need,int remaining){\n", "canonical_solution": " if (need>remaining) return {number+remaining, 0};\n return {number+need,remaining-need};\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(eat(5, 6, 10) , {11, 4}));\n assert (issame(eat(4, 8, 9) , {12, 1}));\n assert (issame(eat(1, 10, 10) , {11, 0}));\n assert (issame(eat(2, 11, 5) , {7, 0}));\n \n assert (issame(eat(4, 5, 7) , {9, 2}));\n assert (issame(eat(4, 5, 1) , {5, 0}));\n}\n", "declaration": "#include<stdio.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nvector<int> eat(int number,int need,int remaining){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(eat(5, 6, 10) , {11, 4}));\n assert (issame(eat(4, 8, 9) , {12, 1}));\n assert (issame(eat(1, 10, 10) , {11, 0}));\n assert (issame(eat(2, 11, 5) , {7, 0}));\n}\n", "buggy_solution": " if (need>remaining) return {number+need+remaining, 0};\n return {number+need,number+remaining-need};\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "eat"}
|
161 |
{"task_id": "CPP/160", "prompt": "/*\nGiven two vectors operator, and operand. The first vector has basic algebra operations, and \nthe second vector is a vector of integers. Use the two given vectors to build the algebric \nexpression and return the evaluation of this expression.\n\nThe basic algebra operations:\nAddition ( + ) \nSubtraction ( - ) \nMultiplication ( * ) \nFloor division ( // ) \nExponentiation ( ** ) \n\nExample:\noperator{\"+\", \"*\", \"-\"}\nvector = {2, 3, 4, 5}\nresult = 2 + 3 * 4 - 5\n=> result = 9\n\nNote:\n The length of operator vector is equal to the length of operand vector minus one.\n Operand is a vector of of non-negative integers.\n Operator vector has at least one operator, and operand vector has at least two operands.\n\n*/\n#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nint do_algebra(vector<string> operato, vector<int> operand){\n", "canonical_solution": " vector<int> num={};\n vector<int> posto={};\n for (int i=0;i<operand.size();i++)\n posto.push_back(i);\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"**\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n operand[posto[i]]=pow(operand[posto[i]],operand[posto[i+1]]);\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"*\" or operato[i]==\"//\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"*\")\n operand[posto[i]]=operand[posto[i]]*operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]/operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"+\" or operato[i]==\"-\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"+\")\n operand[posto[i]]=operand[posto[i]]+operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]-operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n return operand[0];\n\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (do_algebra({\"**\", \"*\", \"+\"}, {2, 3, 4, 5}) == 37);\n assert (do_algebra({\"+\", \"*\", \"-\"}, {2, 3, 4, 5}) == 9);\n assert (do_algebra({\"//\", \"*\"}, {7, 3, 4}) == 8);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nint do_algebra(vector<string> operato, vector<int> operand){\n", "example_test": "", "buggy_solution": " vector<int> num={};\n vector<int> posto={};\n for (int i=0;i<operand.size();i++)\n posto.push_back(i);\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"**\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n operand[posto[i]]=pow(operand[posto[i+1]],operand[posto[i+1]]);\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"*\" or operato[i]==\"//\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"*\")\n operand[posto[i]]=operand[posto[i]]*operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]/operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"+\" or operato[i]==\"-\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"+\")\n operand[posto[i]]=operand[posto[i]]+operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]-operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n return operand[0];\n\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "do_algebra"}
|
|
|
53 |
{"task_id": "CPP/52", "prompt": "/*\nReturn true if all numbers in the vector l are below threshold t.\n>>> below_threshold({1, 2, 4, 10}, 100)\ntrue\n>>> below_threshold({1, 20, 4, 10}, 5)\nfalse\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nbool below_threshold(vector<int>l, int t){\n", "canonical_solution": " for (int i=0;i<l.size();i++)\n if (l[i]>=t) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (below_threshold({1, 2, 4, 10}, 100));\n assert (not(below_threshold({1, 20, 4, 10}, 5)));\n assert (below_threshold({1, 20, 4, 10}, 21));\n assert (below_threshold({1, 20, 4, 10}, 22));\n assert (below_threshold({1, 8, 4, 10}, 11));\n assert (not(below_threshold({1, 8, 4, 10}, 10)));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool below_threshold(vector<int>l, int t){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (below_threshold({1, 2, 4, 10}, 100));\n assert (not(below_threshold({1, 20, 4, 10}, 5)));\n}\n", "buggy_solution": " for (int i=0;i<l.size();i++)\n if (l[i]>=t) return true;\n return false;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "below_threshold"}
|
54 |
{"task_id": "CPP/53", "prompt": "/*\nAdd two numbers x and y\n>>> add(2, 3)\n5\n>>> add(5, 7)\n12\n*/\n#include<stdio.h>\n#include<stdlib.h>\nusing namespace std;\nint add(int x,int y){\n", "canonical_solution": " return x+y;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (add(0, 1) == 1);\n assert (add(1, 0) == 1);\n assert (add(2, 3) == 5);\n assert (add(5, 7) == 12);\n assert (add(7, 5) == 12);\n for (int i=0;i<100;i+=1)\n {\n int x=rand()%1000;\n int y=rand()%1000;\n assert (add(x, y) == x + y);\n }\n}\n", "declaration": "#include<stdio.h>\n#include<stdlib.h>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\nint add(int x,int y){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (add(2, 3) == 5);\n assert (add(5, 7) == 12);\n}\n", "buggy_solution": " return x+y+y+x;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "add"}
|
55 |
{"task_id": "CPP/54", "prompt": "/*\nCheck if two words have the same characters.\n>>> same_chars(\"eabcdzzzz\", \"dddzzzzzzzddeddabc\")\ntrue\n>>> same_chars(\"abcd\", \"dddddddabc\")\ntrue\n>>> same_chars(\"dddddddabc\", \"abcd\")\ntrue\n>>> same_chars(\"eabcd\", \"dddddddabc\")\nfalse\n>>> same_chars(\"abcd\", \"dddddddabce\")\nfalse\n>>> same_chars(\"eabcdzzzz\", \"dddzzzzzzzddddabc\")\nfalse\n*/\n#include<stdio.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\nbool same_chars(string s0,string s1){\n", "canonical_solution": " for (int i=0;i<s0.length();i++)\n if (find(s1.begin(),s1.end(),s0[i])==s1.end())\n return false;\n for (int i=0;i<s1.length();i++)\n if (find(s0.begin(),s0.end(),s1[i])==s0.end())\n return false;\n return true; \n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (same_chars(\"eabcdzzzz\", \"dddzzzzzzzddeddabc\") == true);\n assert (same_chars(\"abcd\", \"dddddddabc\") == true);\n assert (same_chars(\"dddddddabc\", \"abcd\") == true);\n assert (same_chars(\"eabcd\", \"dddddddabc\") == false);\n assert (same_chars(\"abcd\", \"dddddddabcf\") == false);\n assert (same_chars(\"eabcdzzzz\", \"dddzzzzzzzddddabc\") == false);\n assert (same_chars(\"aabb\", \"aaccc\") == false);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool same_chars(string s0,string s1){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (same_chars(\"eabcdzzzz\", \"dddzzzzzzzddeddabc\") == true);\n assert (same_chars(\"abcd\", \"dddddddabc\") == true);\n assert (same_chars(\"dddddddabc\", \"abcd\") == true);\n assert (same_chars(\"eabcd\", \"dddddddabc\") == false);\n assert (same_chars(\"abcd\", \"dddddddabcf\") == false);\n assert (same_chars(\"eabcdzzzz\", \"dddzzzzzzzddddabc\") == false);\n}\n", "buggy_solution": " for (int i=0;i<s0.length();i++)\n if (find(s1.begin(),s1.end(),s0[i])==s1.end())\n return false;\n return true; \n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "same_chars"}
|
56 |
+
{"task_id": "CPP/55", "prompt": "/*\nReturn n-th Fibonacci number.\n>>> fib(10)\n55\n>>> fib(1)\n1\n>>> fib(8)\n21\n*/\n#include<stdio.h>\nusing namespace std;\nint fib(int n){\n", "canonical_solution": " int f[1000];\n f[0]=0;f[1]=1;\n for (int i=2;i<=n; i++)\n f[i]=f[i-1]+f[i-2];\n return f[n];\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (fib(10) == 55);\n assert (fib(1) == 1);\n assert (fib(8) == 21);\n assert (fib(11) == 89);\n assert (fib(12) == 144);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nint fib(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (fib(10) == 55);\n assert (fib(1) == 1);\n assert (fib(8) == 21);\n}\n", "buggy_solution": " int f[1000];\n f[0]=0;f[1]=1;f[2]=2;\n for (int i=3;i<=n; i++)\n f[i]=f[i-1]+f[i-2];\n return f[n];\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "fib"}
|
57 |
{"task_id": "CPP/56", "prompt": "/*\nbrackets is a string of '<' and '>'.\nreturn true if every opening bracket has a corresponding closing bracket.\n\n>>> correct_bracketing(\"<\")\nfalse\n>>> correct_bracketing(\"<>\")\ntrue\n>>> correct_bracketing(\"<<><>>\")\ntrue\n>>> correct_bracketing(\"><<>\")\nfalse\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool correct_bracketing(string brackets){\n", "canonical_solution": " int level=0;\n for (int i=0;i<brackets.length();i++)\n {\n if (brackets[i]=='<') level+=1;\n if (brackets[i]=='>') level-=1;\n if (level<0) return false;\n }\n if (level!=0) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (correct_bracketing(\"<>\"));\n assert (correct_bracketing(\"<<><>>\"));\n assert (correct_bracketing(\"<><><<><>><>\"));\n assert (correct_bracketing(\"<><><<<><><>><>><<><><<>>>\"));\n assert (not (correct_bracketing(\"<<<><>>>>\")));\n assert (not (correct_bracketing(\"><<>\")));\n assert (not (correct_bracketing(\"<\")));\n assert (not (correct_bracketing(\"<<<<\")));\n assert (not (correct_bracketing(\">\")));\n assert (not (correct_bracketing(\"<<>\")));\n assert (not (correct_bracketing(\"<><><<><>><>><<>\")));\n assert (not (correct_bracketing(\"<><><<><>><>>><>\")));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool correct_bracketing(string brackets){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (correct_bracketing(\"<>\"));\n assert (correct_bracketing(\"<<><>>\"));\n assert (not (correct_bracketing(\"><<>\")));\n assert (not (correct_bracketing(\"<\")));\n}\n", "buggy_solution": " int level=0;\n for (int i=0;i<brackets.length();i++)\n {\n if (brackets[i]=='>') level+=1;\n if (brackets[i]=='<') level-=1;\n if (level<0) return false;\n }\n if (level!=0) return false;\n return true;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "correct_bracketing"}
|
58 |
{"task_id": "CPP/57", "prompt": "/*\nReturn true is vector elements are monotonically increasing or decreasing.\n>>> monotonic({1, 2, 4, 20})\ntrue\n>>> monotonic({1, 20, 4, 10})\nfalse\n>>> monotonic({4, 1, 0, -10})\ntrue\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nbool monotonic(vector<float> l){\n", "canonical_solution": " int incr,decr;\n incr=0;decr=0;\n for (int i=1;i<l.size();i++)\n {\n if (l[i]>l[i-1]) incr=1;\n if (l[i]<l[i-1]) decr=1;\n }\n if (incr+decr==2) return false;\n return true;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (monotonic({1, 2, 4, 10}) == true);\n assert (monotonic({1, 2, 4, 20}) == true);\n assert (monotonic({1, 20, 4, 10}) == false);\n assert (monotonic({4, 1, 0, -10}) == true);\n assert (monotonic({4, 1, 1, 0}) == true);\n assert (monotonic({1, 2, 3, 2, 5, 60}) == false);\n assert (monotonic({1, 2, 3, 4, 5, 60}) == true);\n assert (monotonic({9, 9, 9, 9}) == true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool monotonic(vector<float> l){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (monotonic({1, 2, 4, 10}) == true);\n assert (monotonic({1, 20, 4, 10}) == false);\n assert (monotonic({4, 1, 0, -10}) == true);\n}\n", "buggy_solution": " int incr,decr;\n incr=0;decr=0;\n for (int i=1;i<l.size();i++)\n {\n if (l[i]>l[i-1]) incr=1;\n if (l[i]<l[i-1]) decr=1;\n }\n if (incr+decr==2) return true;\n return false;\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "monotonic"}
|
59 |
{"task_id": "CPP/58", "prompt": "/*\nReturn sorted unique common elements for two vectors.\n>>> common({1, 4, 3, 34, 653, 2, 5}, {5, 7, 1, 5, 9, 653, 121})\n{1, 5, 653}\n>>> common({5, 3, 2, 8}, {3, 2})\n{2, 3}\n\n*/\n#include<stdio.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\nvector<int> common(vector<int> l1,vector<int> l2){\n", "canonical_solution": " vector<int> out={};\n for (int i=0;i<l1.size();i++)\n if (find(out.begin(),out.end(),l1[i])==out.end())\n if (find(l2.begin(),l2.end(),l1[i])!=l2.end())\n out.push_back(l1[i]);\n sort(out.begin(),out.end());\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(common({1, 4, 3, 34, 653, 2, 5}, {5, 7, 1, 5, 9, 653, 121}) , {1, 5, 653}));\n assert (issame(common({5, 3, 2, 8}, {3, 2}) , {2, 3}));\n assert (issame(common({4, 3, 2, 8}, {3, 2, 4}) , {2, 3, 4}));\n assert (issame(common({4, 3, 2, 8}, {}) , {}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nvector<int> common(vector<int> l1,vector<int> l2){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(common({1, 4, 3, 34, 653, 2, 5}, {5, 7, 1, 5, 9, 653, 121}) , {1, 5, 653}));\n assert (issame(common({5, 3, 2, 8}, {3, 2}) , {2, 3}));\n}\n", "buggy_solution": " vector<int> out={};\n for (int i=0;i<l1.size();i++)\n if (find(out.begin(),out.end(),l1[i])==out.end())\n out.push_back(l1[i]);\n sort(out.begin(),out.end());\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "common"}
|
|
|
138 |
{"task_id": "CPP/137", "prompt": "/*\nCreate a function that takes integers, floats, or strings representing\nreal numbers, and returns the larger variable in its given variable type.\nReturn \"None\" if the values are equal.\nNote: If a real number is represented as a string, the floating point might be . or ,\n\ncompare_one(1, 2.5) \u279e 2.5\ncompare_one(1, \"2,3\") \u279e \"2,3\"\ncompare_one(\"5,1\", \"6\") \u279e \"6\"\ncompare_one(\"1\", 1) \u279e \"None\"\n*/\n#include<stdio.h>\n#include<string>\n#include<algorithm>\n#include<boost/any.hpp>\nusing namespace std;\nboost::any compare_one(boost::any a,boost::any b){\n", "canonical_solution": " double numa,numb;\n boost::any out;\n \n if (a.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(a);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1);\n numa=atof(s.c_str());\n \n }\n else \n {\n if (a.type()==typeid(int)) numa=boost::any_cast<int>(a);\n if (a.type()==typeid(double)) numa=boost::any_cast<double>(a);\n }\n if (b.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(b);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1);\n numb=atof(s.c_str());\n }\n else \n {\n if (b.type()==typeid(int)) numb=boost::any_cast<int>(b);\n if (b.type()==typeid(double)) numb=boost::any_cast<double>(b);\n }\n\n if (numa==numb) return string(\"None\");\n if (numa<numb) return b;\n if (numa>numb) return a;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (boost::any_cast<int>(compare_one(1, 2)) == 2);\n assert (boost::any_cast<double>(compare_one(1, 2.5))== 2.5);\n assert (boost::any_cast<int>(compare_one(2, 3)) == 3);\n assert (boost::any_cast<int>(compare_one(5, 6)) == 6);\n assert (boost::any_cast<string>(compare_one(1, string(\"2,3\")))== \"2,3\");\n assert (boost::any_cast<string>(compare_one(string(\"5,1\"), string(\"6\"))) == \"6\");\n assert (boost::any_cast<string>(compare_one(string(\"1\"), string(\"2\"))) == \"2\");\n assert (boost::any_cast<string>(compare_one(string(\"1\"), 1)) == \"None\");\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<algorithm>\n#include<boost/any.hpp>\nusing namespace std;\n#include<stdlib.h>\nboost::any compare_one(boost::any a,boost::any b){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (boost::any_cast<double>(compare_one(1, 2.5))== 2.5);\n assert (boost::any_cast<string>(compare_one(1, string(\"2,3\")))== \"2,3\");\n assert (boost::any_cast<string>(compare_one(string(\"5,1\"), string(\"6\"))) == \"6\");\n assert (boost::any_cast<string>(compare_one(string(\"1\"), 1)) == \"None\");\n}\n", "buggy_solution": " double numa,numb;\n boost::any out;\n \n if (a.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(a);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1);\n numa=atof(s.c_str());\n \n }\n else \n {\n if (a.type()==typeid(int)) numa=boost::any_cast<int>(a);\n if (a.type()==typeid(double)) numa=boost::any_cast<double>(a);\n }\n if (b.type()==typeid(string))\n {\n string s;\n s=boost::any_cast<string>(b);\n if (find(s.begin(),s.end(),',')!=s.end())\n for (int i=0;i<s.length();i++)\n if (s[i]==',') s=s.substr(0,i)+'.'+s.substr(i+1)+',';\n numb=atof(s.c_str());\n }\n else \n {\n if (b.type()==typeid(int)) numb=boost::any_cast<int>(b);\n if (b.type()==typeid(double)) numb=boost::any_cast<double>(b);\n }\n\n if (numa==numb) return string(\"None\");\n if (numa<numb) return b;\n if (numa>numb) return a;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "compare_one"}
|
139 |
{"task_id": "CPP/138", "prompt": "/*\nEvaluate whether the given number n can be written as the sum of exactly 4 positive even numbers\nExample\nis_equal_to_sum_even(4) == false\nis_equal_to_sum_even(6) == false\nis_equal_to_sum_even(8) == true\n*/\n#include<stdio.h>\nusing namespace std;\nbool is_equal_to_sum_even(int n){\n", "canonical_solution": " if (n%2==0 and n>=8) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_equal_to_sum_even(4) == false);\n assert (is_equal_to_sum_even(6) == false);\n assert (is_equal_to_sum_even(8) == true);\n assert (is_equal_to_sum_even(10) == true);\n assert (is_equal_to_sum_even(11) == false);\n assert (is_equal_to_sum_even(12) == true);\n assert (is_equal_to_sum_even(13) == false);\n assert (is_equal_to_sum_even(16) == true);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nbool is_equal_to_sum_even(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (is_equal_to_sum_even(4) == false);\n assert (is_equal_to_sum_even(6) == false);\n assert (is_equal_to_sum_even(8) == true);\n}\n", "buggy_solution": " if (n%2==0 and n>=8 and n <=8) return true;\n return false;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "is_equal_to_sum_even"}
|
140 |
{"task_id": "CPP/139", "prompt": "/*\nThe Brazilian factorial is defined as:\nbrazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\nwhere n > 0\n\nFor example:\n>>> special_factorial(4)\n288\n\nThe function will receive an integer as input and should return the special\nfactorial of this integer.\n*/\n#include<stdio.h>\nusing namespace std;\nlong long special_factorial(int n){\n", "canonical_solution": " long long fact=1,bfact=1;\n for (int i=1;i<=n;i++)\n {\n fact=fact*i;\n bfact=bfact*fact;\n }\n return bfact;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (special_factorial(4) == 288);\n assert (special_factorial(5) == 34560);\n assert (special_factorial(7) == 125411328000);\n assert (special_factorial(1) == 1);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nlong long special_factorial(int n){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (special_factorial(4) == 288);\n}\n", "buggy_solution": " long long fact=1,bfact=1;\n for (int i=1;i<=n;i++)\n {\n i=i*n;\n fact=fact*i;\n bfact=bfact*fact;\n }\n return bfact;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "special_factorial"}
|
141 |
+
{"task_id": "CPP/140", "prompt": "/*\nGiven a string text, replace all spaces in it with underscores, \nand if a string has more than 2 consecutive spaces, \nthen replace all consecutive spaces with - \n\nfix_spaces(\"Example\") == \"Example\"\nfix_spaces(\"Example 1\") == \"Example_1\"\nfix_spaces(\" Example 2\") == \"_Example_2\"\nfix_spaces(\" Example 3\") == \"_Example-3\"\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring fix_spaces(string text){\n", "canonical_solution": " string out=\"\";\n int spacelen=0;\n for (int i=0;i<text.length();i++)\n if (text[i]==' ') spacelen+=1;\n else\n {\n if (spacelen==1) out=out+'_';\n if (spacelen==2) out=out+\"__\";\n if (spacelen>2) out=out+'-';\n spacelen=0;\n out=out+text[i];\n }\n if (spacelen==1) out=out+'_';\n if (spacelen==2) out=out+\"__\";\n if (spacelen>2) out=out+'-';\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (fix_spaces(\"Example\") == \"Example\");\n assert (fix_spaces(\"Mudasir Hanif \") == \"Mudasir_Hanif_\");\n assert (fix_spaces(\"Yellow Yellow Dirty Fellow\") == \"Yellow_Yellow__Dirty__Fellow\");\n assert (fix_spaces(\"Exa mple\") == \"Exa-mple\");\n assert (fix_spaces(\" Exa 1 2 2 mple\") == \"-Exa_1_2_2_mple\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring fix_spaces(string text){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (fix_spaces(\"Example\") == \"Example\");\n assert (fix_spaces(\"Example 1\") == \"Example_1\");\n assert (fix_spaces(\" Example 2\") == \"_Example_2\");\n assert (fix_spaces(\" Example 3\") == \"_Example-3\");\n}\n", "buggy_solution": " string out=\"\";\n int spacelen=0;\n for (int i=0;i<text.length();i++)\n if (text[i]==' ') spacelen+=1;\n else\n {\n if (spacelen==1) out=out+'__';\n if (spacelen==2) out=out+\"__\";\n if (spacelen>2) out=out+'--';\n spacelen=0;\n out=out+text[i];\n }\n if (spacelen==1) out=out+'__';\n if (spacelen==2) out=out+\"___\";\n if (spacelen>2) out=out+'--';\n return out;\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "fix_spaces"}
|
142 |
{"task_id": "CPP/141", "prompt": "/*\nCreate a function which takes a string representing a file's name, and returns\n\"Yes\" if the the file's name is valid, and returns \"No\" otherwise.\nA file's name is considered to be valid if and only if all the following conditions \nare met:\n- There should not be more than three digits ('0'-'9') in the file's name.\n- The file's name contains exactly one dot \".\"\n- The substring before the dot should not be empty, and it starts with a letter from \nthe latin alphapet ('a'-'z' and 'A'-'Z').\n- The substring after the dot should be one of these: {'txt\", \"exe\", \"dll\"}\nExamples:\nfile_name_check(\"example.txt\") => \"Yes\"\nfile_name_check(\"1example.dll\") => \"No\" // (the name should start with a latin alphapet letter)\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring file_name_check(string file_name){\n", "canonical_solution": " int numdigit=0,numdot=0;\n if (file_name.length()<5) return \"No\";\n char w=file_name[0];\n if (w<65 or (w>90 and w<97) or w>122) return \"No\";\n string last=file_name.substr(file_name.length()-4,4);\n if (last!=\".txt\" and last!=\".exe\" and last!=\".dll\") return \"No\";\n for (int i=0;i<file_name.length();i++)\n {\n if (file_name[i]>=48 and file_name[i]<=57) numdigit+=1;\n if (file_name[i]=='.') numdot+=1;\n }\n if (numdigit>3 or numdot!=1) return \"No\";\n return \"Yes\"; \n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (file_name_check(\"example.txt\") == \"Yes\");\n assert (file_name_check(\"1example.dll\") == \"No\");\n assert (file_name_check(\"s1sdf3.asd\") == \"No\");\n assert (file_name_check(\"K.dll\") == \"Yes\");\n assert (file_name_check(\"MY16FILE3.exe\") == \"Yes\");\n assert (file_name_check(\"His12FILE94.exe\") == \"No\");\n assert (file_name_check(\"_Y.txt\") == \"No\");\n assert (file_name_check(\"?aREYA.exe\") == \"No\");\n assert (file_name_check(\"/this_is_valid.dll\") == \"No\");\n assert (file_name_check(\"this_is_valid.wow\") == \"No\");\n assert (file_name_check(\"this_is_valid.txt\") == \"Yes\");\n assert (file_name_check(\"this_is_valid.txtexe\") == \"No\");\n assert (file_name_check(\"#this2_i4s_5valid.ten\") == \"No\");\n assert (file_name_check(\"@this1_is6_valid.exe\") == \"No\");\n assert (file_name_check(\"this_is_12valid.6exe4.txt\") == \"No\");\n assert (file_name_check(\"all.exe.txt\") == \"No\");\n assert (file_name_check(\"I563_No.exe\") == \"Yes\");\n assert (file_name_check(\"Is3youfault.txt\") == \"Yes\");\n assert (file_name_check(\"no_one#knows.dll\") == \"Yes\");\n assert (file_name_check(\"1I563_Yes3.exe\") == \"No\");\n assert (file_name_check(\"I563_Yes3.txtt\") == \"No\");\n assert (file_name_check(\"final..txt\") == \"No\");\n assert (file_name_check(\"final132\") == \"No\");\n assert (file_name_check(\"_f4indsartal132.\") == \"No\");\n assert (file_name_check(\".txt\") == \"No\");\n assert (file_name_check(\"s.\") == \"No\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<math.h>\n#include<stdlib.h>\nstring file_name_check(string file_name){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (file_name_check(\"example.txt\") == \"Yes\");\n assert (file_name_check(\"1example.dll\") == \"No\");\n}\n", "buggy_solution": " int numdigit=0,numdot=0;\n if (file_name.length()<5) return \"No\";\n char w=file_name[0];\n if (w<65 or (w>90 and w<97) or w>122) return \"No\";\n string last=file_name.substr(file_name.length()-4,4);\n if (last!=\".txt\" and last!=\".exe\" and last!=\".dll\") return \"No\";\n for (int i=0;i<file_name.length();i++)\n {\n if (file_name[i]>=48 and file_name[i]<=57) numdigit+=1;\n }\n if (numdigit>3 or numdot!=1) return \"No\";\n return \"Yes\"; \n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "file_name_check"}
|
143 |
{"task_id": "CPP/142", "prompt": "/*\n\"\nThis function will take a vector of integers. For all entries in the vector, the function shall square the integer entry if its index is a \nmultiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not \nchange the entries in the vector whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. \n\nExamples:\nFor lst = {1,2,3} the output should be 6\nFor lst = {} the output should be 0\nFor lst = {-1,-5,2,-1,-5} the output should be -126\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nint sum_squares(vector<int> lst){\n", "canonical_solution": " int sum=0;\n for (int i=0;i<lst.size();i++)\n if (i%3==0) sum+=lst[i]*lst[i];\n else if (i%4==0) sum+=lst[i]*lst[i]*lst[i];\n else sum+=lst[i];\n return sum;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (sum_squares({1,2,3}) == 6);\n assert (sum_squares({1,4,9}) == 14);\n assert (sum_squares({}) == 0);\n assert (sum_squares({1,1,1,1,1,1,1,1,1}) == 9);\n assert (sum_squares({-1,-1,-1,-1,-1,-1,-1,-1,-1}) == -3);\n assert (sum_squares({0}) == 0);\n assert (sum_squares({-1,-5,2,-1,-5}) == -126);\n assert (sum_squares({-56,-99,1,0,-2}) == 3030);\n assert (sum_squares({-1,0,0,0,0,0,0,0,-1}) == 0);\n assert (sum_squares({-16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37}) == -14196);\n assert (sum_squares({-1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16, 4, 10}) == -1448);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n#include<stdlib.h>\nint sum_squares(vector<int> lst){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (sum_squares({1,2,3}) == 6);\n assert (sum_squares({}) == 0);\n assert (sum_squares({-1,-5,2,-1,-5}) == -126);\n}\n", "buggy_solution": " int sum=0;\n for (int i=0;i<lst.size();i++)\n if (i%3==0) sum+=lst[i]*lst[i];\n else sum+=lst[i];\n return sum;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sum_squares"}
|
144 |
{"task_id": "CPP/143", "prompt": "/*\nYou are given a string representing a sentence,\nthe sentence contains some words separated by a space,\nand you have to return a string that contains the words from the original sentence,\nwhose lengths are prime numbers,\nthe order of the words in the new string should be the same as the original one.\n\nExample 1:\n Input: sentence = \"This is a test\"\n Output: \"is\"\n\nExample 2:\n Input: sentence = \"lets go for swimming\"\n Output: \"go for\"\n\nConstraints:\n * 1 <= len(sentence) <= 100\n * sentence contains only letters\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nstring words_in_sentence(string sentence){\n", "canonical_solution": " string out=\"\";\n string current=\"\";\n sentence=sentence+' ';\n\n for (int i=0;i<sentence.size();i++)\n if (sentence[i]!=' ') current=current+sentence[i];\n else\n {\n bool isp=true;\n int l=current.length();\n if (l<2) isp=false;\n for (int j=2;j*j<=l;j++)\n if (l%j==0) isp=false;\n if (isp) out=out+current+' ';\n current=\"\"; \n }\n if (out.length()>0)\n out.pop_back();\n return out;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (words_in_sentence(\"This is a test\") == \"is\");\n assert (words_in_sentence(\"lets go for swimming\") == \"go for\");\n assert (words_in_sentence(\"there is no place available here\") == \"there is no place\");\n assert (words_in_sentence(\"Hi I am Hussein\") == \"Hi am Hussein\");\n assert (words_in_sentence(\"go for it\") == \"go for it\");\n assert (words_in_sentence(\"here\") == \"\");\n assert (words_in_sentence(\"here is\") == \"is\");\n}\n", "declaration": "#include<stdio.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring words_in_sentence(string sentence){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (words_in_sentence(\"This is a test\") == \"is\");\n assert (words_in_sentence(\"lets go for swimming\") == \"go for\");\n}\n", "buggy_solution": " string out=\"\";\n string current=\"\";\n sentence=sentence+' ';\n\n for (int i=0;i<sentence.size();i++)\n if (sentence[i]!=' ') current=current+sentence[i];\n else\n {\n bool isp=true;\n int l=current.length();\n if (l<2) isp=false;\n for (int j=2;j*j<=l;j++)\n if (l%j==0) isp=false;\n if (isp) out=out+current+' ';\n current=\"\"; \n }\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "words_in_sentence"}
|
|
|
155 |
{"task_id": "CPP/154", "prompt": "/*\nYou are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word\ncycpattern_check(\"abcd\",\"abd\") => false\ncycpattern_check(\"hello\",\"ell\") => true\ncycpattern_check(\"whassup\",\"psus\") => false\ncycpattern_check(\"abab\",\"baa\") => true\ncycpattern_check(\"efef\",\"eeff\") => false\ncycpattern_check(\"himenss\",'simen\") => true\n\n*/\n#include<stdio.h>\n#include<string>\nusing namespace std;\nbool cycpattern_check(string a,string b){\n", "canonical_solution": " for (int i=0;i<b.size();i++)\n {\n string rotate=b.substr(i)+b.substr(0,i);\n if (a.find(rotate)!=string::npos) return true;\n }\n return false;\n\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (cycpattern_check(\"xyzw\",\"xyw\") == false );\n assert (cycpattern_check(\"yello\",\"ell\") == true );\n assert (cycpattern_check(\"whattup\",\"ptut\") == false );\n assert (cycpattern_check(\"efef\",\"fee\") == true );\n assert (cycpattern_check(\"abab\",\"aabb\") == false );\n assert (cycpattern_check(\"winemtt\",\"tinem\") == true );\n}\n", "declaration": "#include<stdio.h>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nbool cycpattern_check(string a,string b){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (cycpattern_check(\"abcd\",\"abd\") == false );\n assert (cycpattern_check(\"hello\",\"ell\") == true );\n assert (cycpattern_check(\"whassup\",\"psus\") == false );\n assert (cycpattern_check(\"abab\",\"baa\") == true );\n assert (cycpattern_check(\"efef\",\"eeff\") == false );\n assert (cycpattern_check(\"himenss\",\"simen\") == true );\n}\n", "buggy_solution": " for (int i=0;i<b.size();i++)\n {\n string rotate=b.substr(i)+b.substr(0);\n if (a.find(rotate)!=string::npos) return true;\n }\n return false;\n\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "cycpattern_check"}
|
156 |
{"task_id": "CPP/155", "prompt": "/*\nGiven an integer. return a vector that has the number of even and odd digits respectively.\n\n Example:\n even_odd_count(-12) ==> {1, 1}\n even_odd_count(123) ==> {1, 2}\n*/\n#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<vector>\nusing namespace std;\nvector<int> even_odd_count(int num){\n", "canonical_solution": " string w=to_string(abs(num));\n int n1=0,n2=0;\n for (int i=0;i<w.length();i++)\n if (w[i]%2==1) n1+=1;\n else n2+=1;\n return {n2,n1};\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(even_odd_count(7) , {0, 1}));\n assert (issame(even_odd_count(-78) , {1, 1}));\n assert (issame(even_odd_count(3452) , {2, 2}));\n assert (issame(even_odd_count(346211) , {3, 3}));\n assert (issame(even_odd_count(-345821) , {3, 3}));\n assert (issame(even_odd_count(-2) , {1, 0}));\n assert (issame(even_odd_count(-45347) , {2, 3}));\n assert (issame(even_odd_count(0) , {1, 0}));\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<string>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nvector<int> even_odd_count(int num){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(even_odd_count(-12) , {1, 1}));\n assert (issame(even_odd_count(123) , {1, 2}));\n}\n", "buggy_solution": " string w=to_string(abs(num));\n int n1=0,n2=0;\n for (int i=0;i<w.length();i++)\n if (w[i]%2==1) n1+=1;\n return {n2,n1};\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "even_odd_count"}
|
157 |
{"task_id": "CPP/156", "prompt": "/*\nGiven a positive integer, obtain its roman numeral equivalent as a string,\nand return it in lowercase.\nRestrictions: 1 <= num <= 1000\n\nExamples:\n>>> int_to_mini_roman(19) == \"xix\"\n>>> int_to_mini_roman(152) == \"clii\"\n>>> int_to_mini_roman(426) == \"cdxxvi\"\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\nstring int_to_mini_romank(int number){\n", "canonical_solution": " string current=\"\";\n vector<string> rep={\"m\",\"cm\",\"d\",\"cd\",\"c\",\"xc\",\"l\",\"xl\",\"x\",\"ix\",\"v\",\"iv\",\"i\"};\n vector<int> num={1000,900,500,400,100,90,50,40,10,9,5,4,1};\n int pos=0;\n while(number>0)\n {\n while (number>=num[pos])\n {\n current=current+rep[pos];\n number-=num[pos];\n }\n if (number>0) pos+=1;\n }\n return current;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (int_to_mini_romank(19) == \"xix\");\n assert (int_to_mini_romank(152) == \"clii\");\n assert (int_to_mini_romank(251) == \"ccli\");\n assert (int_to_mini_romank(426) == \"cdxxvi\");\n assert (int_to_mini_romank(500) == \"d\");\n assert (int_to_mini_romank(1) == \"i\");\n assert (int_to_mini_romank(4) == \"iv\");\n assert (int_to_mini_romank(43) == \"xliii\");\n assert (int_to_mini_romank(90) == \"xc\");\n assert (int_to_mini_romank(94) == \"xciv\");\n assert (int_to_mini_romank(532) == \"dxxxii\");\n assert (int_to_mini_romank(900) == \"cm\");\n assert (int_to_mini_romank(994) == \"cmxciv\");\n assert (int_to_mini_romank(1000) == \"m\");\n}\n", "declaration": "#include<stdio.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nstring int_to_mini_romank(int number){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (int_to_mini_romank(19) == \"xix\");\n assert (int_to_mini_romank(152) == \"clii\");\n assert (int_to_mini_romank(426) == \"cdxxvi\");\n}\n", "buggy_solution": " string current=\"\";\n vector<string> rep={\"m\",\"cm\",\"d\",\"cd\",\"c\",\"xc\",\"l\",\"xl\",\"x\",\"ix\",\"v\",\"iv\",\"i\"};\n vector<int> num={1000,900,500,400,100,90,50,40,10,9,5,4,1};\n int pos=0;\n while(number>0)\n {\n while (number>=num[pos])\n {\n current=current+rep[pos];\n }\n if (number>0) pos+=1;\n }\n return current;\n}\n", "bug_type": "missing logic", "failure_symptoms": "infinite loop", "entry_point": "int_to_mini_roman"}
|
158 |
+
{"task_id": "CPP/157", "prompt": "/*\nGiven the lengths of the three sides of a triangle. Return true if the three\nsides form a right-angled triangle, false otherwise.\nA right-angled triangle is a triangle in which one angle is right angle or \n90 degree.\nExample:\nright_angle_triangle(3, 4, 5) == true\nright_angle_triangle(1, 2, 3) == false\n*/\n#include<stdio.h>\n#include<math.h>\nusing namespace std;\nbool right_angle_triangle(float a,float b,float c){\n", "canonical_solution": " if (abs(a*a+b*b-c*c)<1e-4 or abs(a*a+c*c-b*b)<1e-4 or abs(b*b+c*c-a*a)<1e-4) return true;\n return false;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (right_angle_triangle(3, 4, 5) == true);\n assert (right_angle_triangle(1, 2, 3) == false);\n assert (right_angle_triangle(10, 6, 8) == true);\n assert (right_angle_triangle(2, 2, 2) == false);\n assert (right_angle_triangle(7, 24, 25) == true);\n assert (right_angle_triangle(10, 5, 7) == false);\n assert (right_angle_triangle(5, 12, 13) == true);\n assert (right_angle_triangle(15, 8, 17) == true);\n assert (right_angle_triangle(48, 55, 73) == true);\n assert (right_angle_triangle(1, 1, 1) == false);\n assert (right_angle_triangle(2, 2, 10) == false);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nbool right_angle_triangle(float a,float b,float c){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (right_angle_triangle(3, 4, 5) == true);\n assert (right_angle_triangle(1, 2, 3) == false);\n}\n", "buggy_solution": " if (abs(a*a+b*b-c*c)<1e-4) return true;\n return false;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "right_angle_triangle"}
|
159 |
{"task_id": "CPP/158", "prompt": "/*\nWrite a function that accepts a vector of strings.\nThe vector contains different words. Return the word with maximum number\nof unique characters. If multiple strings have maximum number of unique\ncharacters, return the one which comes first in lexicographical order.\n\nfind_max({\"name\", \"of\", 'string\"}) == 'string\"\nfind_max({\"name\", \"enam\", \"game\"}) == \"enam\"\nfind_max({\"aaaaaaa\", \"bb\" ,\"cc\"}) == \"aaaaaaa\"\n*/\n#include<stdio.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\nstring find_max(vector<string> words){\n", "canonical_solution": " string max=\"\";\n int maxu=0;\n for (int i=0;i<words.size();i++)\n {\n string unique=\"\";\n for (int j=0;j<words[i].length();j++)\n if (find(unique.begin(),unique.end(),words[i][j])==unique.end())\n unique=unique+words[i][j];\n if (unique.length()>maxu or (unique.length()==maxu and words[i]<max))\n {\n max=words[i];\n maxu=unique.length();\n }\n }\n return max;\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert ((find_max({\"name\", \"of\", \"string\"}) == \"string\"));\n assert ((find_max({\"name\", \"enam\", \"game\"}) == \"enam\"));\n assert ((find_max({\"aaaaaaa\", \"bb\", \"cc\"}) == \"aaaaaaa\"));\n assert ((find_max({\"abc\", \"cba\"}) == \"abc\"));\n assert ((find_max({\"play\", \"this\", \"game\", \"of\",\"footbott\"}) == \"footbott\"));\n assert ((find_max({\"we\", \"are\", \"gonna\", \"rock\"}) == \"gonna\"));\n assert ((find_max({\"we\", \"are\", \"a\", \"mad\", \"nation\"}) == \"nation\"));\n assert ((find_max({\"this\", \"is\", \"a\", \"prrk\"}) == \"this\"));\n assert ((find_max({\"b\"}) == \"b\"));\n assert ((find_max({\"play\", \"play\", \"play\"}) == \"play\"));\n}\n", "declaration": "#include<stdio.h>\n#include<vector>\n#include<string>\n#include<algorithm>\nusing namespace std;\n#include<math.h>\n#include<stdlib.h>\nstring find_max(vector<string> words){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert ((find_max({\"name\", \"of\", \"string\"}) == \"string\"));\n assert ((find_max({\"name\", \"enam\", \"game\"}) == \"enam\"));\n assert ((find_max({\"aaaaaaa\", \"bb\", \"cc\"}) == \"aaaaaaa\"));\n}\n", "buggy_solution": " string max=\"\";\n int maxu=0;\n for (int i=0;i<words.size();i++)\n {\n string unique=\"\";\n for (int j=0;j<words[i].length();j++)\n if (find(unique.begin(),unique.end(),words[i][j])==unique.end())\n unique=unique+words[i][j];\n if (unique.length()>maxu or unique.length()==maxu)\n {\n max=words[i];\n maxu=unique.length();\n }\n }\n return max;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "find_max"}
|
160 |
{"task_id": "CPP/159", "prompt": "/*\nYou\"re a hungry rabbit, and you already have eaten a certain number of carrots,\nbut now you need to eat more carrots to complete the day's meals.\nyou should return a vector of { total number of eaten carrots after your meals,\n the number of carrots left after your meals }\nif there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.\n\nExample:\n* eat(5, 6, 10) -> {11, 4}\n* eat(4, 8, 9) -> {12, 1}\n* eat(1, 10, 10) -> {11, 0}\n* eat(2, 11, 5) -> {7, 0}\n\nVariables:\n@number : integer\n the number of carrots that you have eaten.\n@need : integer\n the number of carrots that you need to eat.\n@remaining : integer\n the number of remaining carrots thet exist in stock\n\nConstrain:\n* 0 <= number <= 1000\n* 0 <= need <= 1000\n* 0 <= remaining <= 1000\n\nHave fun :)\n*/\n#include<stdio.h>\n#include<vector>\nusing namespace std;\nvector<int> eat(int number,int need,int remaining){\n", "canonical_solution": " if (need>remaining) return {number+remaining, 0};\n return {number+need,remaining-need};\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(eat(5, 6, 10) , {11, 4}));\n assert (issame(eat(4, 8, 9) , {12, 1}));\n assert (issame(eat(1, 10, 10) , {11, 0}));\n assert (issame(eat(2, 11, 5) , {7, 0}));\n \n assert (issame(eat(4, 5, 7) , {9, 2}));\n assert (issame(eat(4, 5, 1) , {5, 0}));\n}\n", "declaration": "#include<stdio.h>\n#include<vector>\nusing namespace std;\n#include<algorithm>\n#include<math.h>\n#include<stdlib.h>\nvector<int> eat(int number,int need,int remaining){\n", "example_test": "#undef NDEBUG\n#include<assert.h>\nbool issame(vector<int> a,vector<int>b){\n if (a.size()!=b.size()) return false;\n for (int i=0;i<a.size();i++)\n {\n if (a[i]!=b[i]) return false;\n }\n return true;\n}\nint main(){\n assert (issame(eat(5, 6, 10) , {11, 4}));\n assert (issame(eat(4, 8, 9) , {12, 1}));\n assert (issame(eat(1, 10, 10) , {11, 0}));\n assert (issame(eat(2, 11, 5) , {7, 0}));\n}\n", "buggy_solution": " if (need>remaining) return {number+need+remaining, 0};\n return {number+need,number+remaining-need};\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "eat"}
|
161 |
{"task_id": "CPP/160", "prompt": "/*\nGiven two vectors operator, and operand. The first vector has basic algebra operations, and \nthe second vector is a vector of integers. Use the two given vectors to build the algebric \nexpression and return the evaluation of this expression.\n\nThe basic algebra operations:\nAddition ( + ) \nSubtraction ( - ) \nMultiplication ( * ) \nFloor division ( // ) \nExponentiation ( ** ) \n\nExample:\noperator{\"+\", \"*\", \"-\"}\nvector = {2, 3, 4, 5}\nresult = 2 + 3 * 4 - 5\n=> result = 9\n\nNote:\n The length of operator vector is equal to the length of operand vector minus one.\n Operand is a vector of of non-negative integers.\n Operator vector has at least one operator, and operand vector has at least two operands.\n\n*/\n#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nint do_algebra(vector<string> operato, vector<int> operand){\n", "canonical_solution": " vector<int> num={};\n vector<int> posto={};\n for (int i=0;i<operand.size();i++)\n posto.push_back(i);\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"**\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n operand[posto[i]]=pow(operand[posto[i]],operand[posto[i+1]]);\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"*\" or operato[i]==\"//\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"*\")\n operand[posto[i]]=operand[posto[i]]*operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]/operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"+\" or operato[i]==\"-\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"+\")\n operand[posto[i]]=operand[posto[i]]+operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]-operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n return operand[0];\n\n}\n", "test": "#undef NDEBUG\n#include<assert.h>\nint main(){\n assert (do_algebra({\"**\", \"*\", \"+\"}, {2, 3, 4, 5}) == 37);\n assert (do_algebra({\"+\", \"*\", \"-\"}, {2, 3, 4, 5}) == 9);\n assert (do_algebra({\"//\", \"*\"}, {7, 3, 4}) == 8);\n}\n", "declaration": "#include<stdio.h>\n#include<math.h>\n#include<vector>\n#include<string>\nusing namespace std;\n#include<algorithm>\n#include<stdlib.h>\nint do_algebra(vector<string> operato, vector<int> operand){\n", "example_test": "", "buggy_solution": " vector<int> num={};\n vector<int> posto={};\n for (int i=0;i<operand.size();i++)\n posto.push_back(i);\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"**\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n operand[posto[i]]=pow(operand[posto[i+1]],operand[posto[i+1]]);\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"*\" or operato[i]==\"//\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"*\")\n operand[posto[i]]=operand[posto[i]]*operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]/operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n for (int i=0;i<operato.size();i++)\n if (operato[i]==\"+\" or operato[i]==\"-\") \n {\n while (posto[posto[i]]!=posto[i]) posto[i]=posto[posto[i]];\n while (posto[posto[i+1]]!=posto[i+1]) posto[i+1]=posto[posto[i+1]];\n if (operato[i]==\"+\")\n operand[posto[i]]=operand[posto[i]]+operand[posto[i+1]];\n else\n operand[posto[i]]=operand[posto[i]]-operand[posto[i+1]];\n posto[i+1]=posto[i];\n }\n return operand[0];\n\n}\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "do_algebra"}
|