doc_id
stringlengths
36
36
metadata
dict
input
stringlengths
28
4.3k
output
stringlengths
11
5.45k
02c377c0-b82e-475a-80c8-67325d2c5d5b
{ "language": "C++" }
```c++ ``` Update Interview question twitter microsoft
```c++ #include <iostream> #include<algorithm> using namespace std; class interval { int start; int duration; }; bool myCompare(interval a, interval b) { return a.start<b.start; } bool conflict(interval a, int timestamp) { if(a.start <= timestamp && (a.start + a.duration >= timestamp ) ) retu...
a541effc-712b-4d9c-a3bb-1e23002a5ad9
{ "language": "C++" }
```c++ ``` Add Chapter 24, exercise 2
```c++ // Chapter 24, exercise 2: same as exercise 1, but with function objects // instead of functions #include<iostream> #include "Matrix.h" #include "MatrixIO.h" using namespace std; using namespace Numeric_lib; namespace Numeric_lib {; struct Triple1 { void operator()(int& a) { a *= 3; } }; struct Triple2 ...
5e0dcbdb-86df-4f27-a33f-e08ce5b07d47
{ "language": "C++" }
```c++ ``` Add missing file from last commit.
```c++ /* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required...
8dbaeab8-f39f-43d1-bee1-e19aac95d62d
{ "language": "C++" }
```c++ ``` Swap nodes in a pair
```c++ #include "lib/list.cpp" using namespace std; ListNode* swapNodes(ListNode* head) { if (head == NULL || head->next == NULL) { return head; } ListNode* fakeHead = new ListNode(0); fakeHead->next = head; ListNode* prev = fakeHead; ListNode* current = head; ListNode* temp; ...
99b67d8c-9ac0-4b15-9276-29f1fdd07067
{ "language": "C++" }
```c++ ``` Add unit test of DistField class
```c++ /** * @file TestDistField.cpp * @brief Unit test of DistField class * @author cromod * @date september 2015 */ #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE TestDistField #include <boost/test/unit_test.hpp> #include <iostream> #include "DistField.hpp" #include "Exception.hpp" using namespace Crom...
8f22adbd-b9a0-4f0f-99ab-2a718d1613c9
{ "language": "C++" }
```c++ ``` Add solution for chapter 17 test 35
```c++ #include <iostream> #include <cmath> using namespace std; int main() { cout << uppercase << hexfloat; cout << sqrt(2) << endl; return 0; } ```
035a599d-a09b-41c6-9d6a-1a76edccd160
{ "language": "C++" }
```c++ ``` Check if One String Swap Can Make Strings Equal
```c++ class Solution { public: bool areAlmostEqual(string s1, string s2) { size_t index = 0, count = 0; std::vector<size_t> arr; while (index < s1.size()) { if (s1[index] != s2[index]) { ++count; if (count > 2) return false; ...
f3757b58-b9bc-48ad-a879-58105de8086a
{ "language": "C++" }
```c++ //------------------------------------------------------------------------------ // Clock.cc //------------------------------------------------------------------------------ #include "Pre.h" #include "Clock.h" #if ORYOL_EMSCRIPTEN #include <emscripten/emscripten.h> #else #include <chrono> #endif n...
```c++ //------------------------------------------------------------------------------ // Clock.cc //------------------------------------------------------------------------------ #include "Pre.h" #include "Clock.h" #if ORYOL_EMSCRIPTEN #include <emscripten/emscripten.h> #elif ORYOL_WINDOWS #include <Windows....
1ee33389-ec4e-455a-901d-aae4f0742a47
{ "language": "C++" }
```c++ ``` Add missing test from r163874.
```c++ // RUN: %clang_cc1 -verify -Wunused -Wused-but-marked-unused -fsyntax-only %s namespace ns_unused { typedef int Int_unused __attribute__((unused)); } namespace ns_not_unused { typedef int Int_not_unused; } void f() { ns_not_unused::Int_not_unused i1; // expected-warning {{unused variable}} ns_unused::Int_u...
9a86a9ed-ebcd-45cf-8988-b9f42ce2eb37
{ "language": "C++" }
```c++ ``` Add Solution for 237 Delete Node in a Linked List
```c++ // 237. Delete Node in a Linked List /** * Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. * * Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4 * after calling y...
13fd8909-503b-416c-a868-235f9312b58b
{ "language": "C++" }
```c++ #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE JPetTaskLoaderTest #include <boost/test/unit_test.hpp> #define private public #include "../../JPetTaskLoader/JPetTaskLoader.h" BOOST_AUTO_TEST_SUITE(FirstSuite) BOOST_AUTO_TEST_CASE( my_test1 ) { BOOST_REQUIRE(1==0); } BOOST_AUTO_TEST_SUITE_END() ``` C...
```c++ #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE JPetTaskLoaderTest #include <boost/test/unit_test.hpp> #define private public #include "../../JPetTaskLoader/JPetTaskLoader.h" BOOST_AUTO_TEST_SUITE(FirstSuite) BOOST_AUTO_TEST_CASE(defaultConstrutocTest) { /*JPetOptions::Options options = { {"in...
7b828faa-6452-4692-aa64-e2b586374a7a
{ "language": "C++" }
```c++ ``` Add error test for func wrapper
```c++ #include "Halide.h" using namespace Halide; using namespace Halide::Internal; int main() { Var x("x"), y("y"); Func f("f"), g("g"), h("h"); f(x, y) = x + y; g(x, y) = 5; h(x, y) = f(x, y) + g(x, y); f.compute_root(); f.in(g).compute_root(); // This should cause an error since ...
0b925c5c-b0f9-438c-9a0b-847c165de2de
{ "language": "C++" }
```c++ ``` Add some tests for worker thread implementation
```c++ // Copyright 2012-2013 Samplecount S.L. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law...
b4dc1551-b22f-4a8a-8a16-3951c6acd6f2
{ "language": "C++" }
```c++ ``` Add the solution to "Lego Blocks".
```c++ #include <iostream> #include <cstring> #define MODULO 1000000007 #define MAX 1001 using namespace std; long long mod_add(long long x, long long y) { return (x + y) % MODULO; } long long mod_sub(long long x, long long y) { return (x - y + MODULO) % MODULO; } long long mod_mult(long long x, long long y) { re...
6e913ea2-2f41-458e-8284-b7e3cd9ff188
{ "language": "C++" }
```c++ ``` Add Chapter 27, exercise 8
```c++ // Chapter 27, exercise 8: write out every character on your keyboard together // with its integer value; then, write the characters out in the order deter- // mined by their integer value #include<iostream> #include<string> #include<algorithm> using namespace std; void print(const string& s) { for (int i...
fd486c71-1221-44a2-941d-8e481c6abf30
{ "language": "C++" }
```c++ ``` Add alternative game, you know
```c++ #include <iostream> #include <string> #include <vector> #include <algorithm> #include <random> static std::random_device rd; static std::mt19937 gen(rd()); static std::uniform_int_distribution<> dist(5, 30); static std::uniform_int_distribution<> negator(0, 1); static std::uniform_int_distribution<> d...
2071dbc3-6a8d-4236-9546-8b964d3e6c31
{ "language": "C++" }
```c++ ``` Add test case for PR6141, which was fixed a few days ago
```c++ // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s // PR6141 template<typename T> struct X { X(); template<typename U> X(X<U>); X(const X<T>&); }; void f(X<int>) { } struct Y : X<int> { }; struct Z : X<float> { }; // CHECK: define i32 @main() int main() { // CHECK: cal...
153cb933-1344-47e7-8919-d7a2ae87505d
{ "language": "C++" }
```c++ ``` Add test file for tcpserver
```c++ #include <gtest/gtest.h> #include "tcpserver.hpp" using namespace OpenSofa; namespace { TEST(TCPServerTest, CanBeCreated) { Server * server = new TCPServer(); delete server; } } ```
9845d615-e612-482f-96d6-ecb1b32539a7
{ "language": "C++" }
```c++ ``` Build first-party C++ deps of OSS React Native with Buck
```c++ /* * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ #ifn...
862e9c4c-e587-4527-80eb-1bb2ed340a3a
{ "language": "C++" }
```c++ ``` Add variadic template arguments example in c++17.
```c++ #include <iostream> void foo() { std::cout << __PRETTY_FUNCTION__ << "\n"; std::cout << " "; } template <typename Arg> void foo(Arg arg) { std::cout << __PRETTY_FUNCTION__ << "\n"; std::cout << arg << " "; } template <typename First, typename... Args> void foo(First first, Args... args) { ...
bfc52fa1-74af-4edd-903a-a65426e8c32d
{ "language": "C++" }
```c++ ``` Prepare test case for dbn_fast
```c++ //======================================================================= // Copyright (c) 2014-2016 Baptiste Wicht // Distributed under the terms of the MIT License. // (See accompanying file LICENSE or copy at // http://opensource.org/licenses/MIT) //===========================================================...
4815d0cb-4f8c-4f68-8225-97a96d1126f9
{ "language": "C++" }
```c++ ``` Fix bug in __libcpp_db::__iterator_copy. Add debug test for swaping lists.
```c++ //===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===---------------------------------...
ef617def-391d-4a13-8675-c1d999dc796a
{ "language": "C++" }
```c++ #include "listener.h" #include "log.h" #include "buffers.h" void conditionalEnqueue(QUEUE_TYPE(uint8_t)* queue, uint8_t* message, int messageSize) { if(queue_available(queue) < messageSize + 1) { debug("Dropped incoming CAN message -- send queue full\r\n"); return; } ...
```c++ #include "listener.h" #include "log.h" #include "buffers.h" void conditionalEnqueue(QUEUE_TYPE(uint8_t)* queue, uint8_t* message, int messageSize) { if(queue_available(queue) < messageSize + 2) { debug("Dropped incoming CAN message -- send queue full\r\n"); return; } ...
47c84d2a-06fa-4736-b856-91a39e401f76
{ "language": "C++" }
```c++ ``` Fix glitch with Clang and boost
```c++ //======================================================================= // Copyright Baptiste Wicht 2011-2013. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) //=========================================...
73894b73-7c3c-462a-afcc-32ebfd844fd2
{ "language": "C++" }
```c++ ``` Add command to test timer (to be deleted on next commit)
```c++ #include "command.h" #include "timer.h" #include <ctime> #include <unistd.h> using namespace MR; using namespace App; void usage () { DESCRIPTION + "test timer interface"; REQUIRES_AT_LEAST_ONE_ARGUMENT = false; } void run () { Timer timer; CONSOLE ("printing Timer::current_time() at 10ms i...
c6a71778-524e-423f-912f-47fdcda386a2
{ "language": "C++" }
```c++ ``` Add missing test case for operator ! result type.
```c++ // RUN: clang -fsyntax-only -verify %s void choice(int); int choice(bool); void test() { // Result of ! must be type bool. int i = choice(!1); } ```
9b2366ef-6d4d-47f6-b0b2-25912f11d9b0
{ "language": "C++" }
```c++ ``` Add initial 5-minute hack simulation script.
```c++ #include <iostream> #include <random> #define MAX_NUM_ROWS 10 #define NUM_ITERS 1000 #define BLOCK_SIZE 512 // cache line size in bits. #define NUM_BLOCKS 10000 #define NUM_DOCS BLOCK_SIZE * NUM_BLOCKS // DESIGN NOTE: tried using go, but the publicly available binomial rng is approximately 10x slower. // TODO:...
f740ce87-9e0c-4b0c-abd7-1da0972323c3
{ "language": "C++" }
```c++ ``` Add Chapter 21, exercise 6
```c++ // Chapter 21, Exercise 6: implement the Fruit example (set) using a // set<Fruit*,Fruit_comparison> (pointers instead of copies), i.e., define a // comparison operation for Fruit* #include "../lib_files/std_lib_facilities.h" #include<set> //---------------------------------------------------------------------...
ce85e281-cf32-4271-9ea5-52cda7ae0d41
{ "language": "C++" }
```c++ ``` Print Left View of the tree.
```c++ #include <stdio.h> typedef struct _NODE { int data; _NODE* left; _NODE* right; } NODE; NODE* newNode(int data) { NODE* node = new NODE(); node->data = data; node->left = nullptr; node->right = nullptr; return node; } void leftViewUtil(NODE* root, int level, int* max_level) { if (root == nul...
fda00cfe-c3e8-409b-a85e-2bdd215f9c0e
{ "language": "C++" }
```c++ ``` Add small test program for base64 decoding.
```c++ #include "base64inputstream.h" #include <stdio.h> using namespace jstreams; using namespace std; int main(int argc, char** argv) { for (int i=1; i<argc; ++i) { string out = Base64InputStream::decode(argv[i], strlen(argv[i])); printf("%s\n", out.c_str()); } return 0; } ```
5e0860a2-3f3a-49bd-a6b5-3f81dc2c7580
{ "language": "C++" }
```c++ ``` Add queue implemented with 2 stacks
```c++ #include <iostream> #include <stack> using std::cout; using std::endl; using std::stack; class Queue { stack<int> stackIn, stackOut; void transfer() { while (!stackIn.empty()) { stackOut.push(stackIn.top()); stackIn.pop(); } } public: bool empty() { return st...
da75e856-6e3c-4a9a-9ed0-d6f4a50e621e
{ "language": "C++" }
```c++ ``` Add 141 Linked List Cycle
```c++ // 141 Linked List Cycle /** * Given a linked list, determine if it has a cycle in it. * * Follow up: * Can you solve it without using extra space? * * Tag: Linked List, Two Pointers * * Author: Yanbin Lu */ #include <stddef.h> #include <vector> #include <string.h> #include <stdio.h> #include <algorithm> ...
9f4278fd-f5c2-4188-8028-4dc2b825cc54
{ "language": "C++" }
```c++ ``` Add a test that makes sure coverage works at least in the simple cases
```c++ // RUN: rm -rf %T/coverage-basic // RUN: mkdir %T/coverage-basic && cd %T/coverage-basic // RUN: %clangxx_asan -fsanitize-coverage=1 %s -o test.exe // RUN: env ASAN_OPTIONS=coverage=1 %run test.exe // // RUN: %sancov print *.sancov | FileCheck %s #include <stdio.h> void foo() { fprintf(stderr, "FOO\n"); } void ...
04ff2736-85e6-43c9-aa50-0366eb610b16
{ "language": "C++" }
```c++ ``` Copy List with Random Pointer
```c++ /* // Definition for a Node. class Node { public: int val; Node* next; Node* random; Node(int _val) { val = _val; next = NULL; random = NULL; } }; */ class Solution { public: Node* copyRandomList(Node* head) { if (!head) return nullptr; Node* ...
29af0522-a974-4907-88f9-a8c51126d8b3
{ "language": "C++" }
```c++ ``` Add Solution for 454 4Sum II
```c++ // 454. 4Sum II /** * Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero. * * To make problem a bit easier, all A, B, C, D have same length of N where 0 <= N <= 500. All integers are in the range of -2^28 to 2^28 - 1 * a...
2bde71df-6d38-46a7-a690-f9d656c2aba9
{ "language": "C++" }
```c++ ``` Add Printing k digits of 1/n
```c++ /* * Copyright 2010, NagaChaitanya Vellanki * * Author NagaChaitanya Vellanki * * Print k digits of decimal representation of 1/n for n > 1 */ #include <inttypes.h> #include <iostream> #include <cstdlib> using namespace std; int main() { int32_t n = 0; int32_t k = 1; cout << "Enter n(n > 1) and n...
12150464-4d68-410a-9e62-be9fcd4ddd7b
{ "language": "C++" }
```c++ ``` Add sample solution to the first problem for the first test
```c++ #include <iostream> #include <cstring> using namespace std; class Ticket { int seat; int price; public: Ticket(int _seat) : seat(_seat) { if (seat >= 1 && seat <= 30) price = 70; else if (seat >= 31 && seat <= 70) price = 55; else if (seat >= 71 && ...
61f82c10-2b6c-44ac-b66c-2b404b248192
{ "language": "C++" }
```c++ ``` Add another windows test case.
```c++ /* * This test demonstrates that putting a console into selection mode does not * block the low-level console APIs, even though it blocks WriteFile. */ #define _WIN32_WINNT 0x0501 #include "../Shared/DebugClient.cc" #include <windows.h> #include <stdio.h> const int SC_CONSOLE_MARK = 0xFFF2; CALLBACK DWORD ...
0f540fa1-908b-44ec-8fb7-957161d324fe
{ "language": "C++" }
```c++ // Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/android/jni_registrar.h" #include "base/logging.h" #include "base/android/jni_android.h" namespace base { namespace android { ...
```c++ // Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/android/jni_registrar.h" #include "base/logging.h" #include "base/android/jni_android.h" namespace base { namespace android { ...
712abc56-d329-4429-b3ac-9f9f1c19c993
{ "language": "C++" }
```c++ ``` Implement cell-refinement of triangular cartesian 2D cells.
```c++ #include "cell_refine.hpp" #include <viennagrid/algorithm/refine.hpp> /*************** * CELL_REFINE * ***************/ // Triangular tuple TriangularCartesian2D_Domain_cell_refine(TriangularCartesian2D_Domain domain_in, TriangularCartesian2D_Segmentation segmentation_in, bool (*predicate)(const Triangular...
7bd8e72e-28fa-401e-ac3e-3ce16892dff0
{ "language": "C++" }
```c++ ``` Add test for autoencoder with RBM pretraining
```c++ //======================================================================= // Copyright (c) 2014-2015 Baptiste Wicht // Distributed under the terms of the MIT License. // (See accompanying file LICENSE or copy at // http://opensource.org/licenses/MIT) //===========================================================...
a2d8765a-d4c4-41aa-b61f-107a3b71c323
{ "language": "C++" }
```c++ ``` Add Solution 006 ZigZag Conversion
```c++ // 6. ZigZag Conversion /** * The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: * (you may want to display this pattern in a fixed font for better legibility) * * P A H N * A P L S I I G * Y I R * * And then read line by line: "PAHNAPLSIIGYIR" *...
749768e5-e6a6-4bd8-916c-1d1dfdab9bda
{ "language": "C++" }
```c++ ``` Add a test for PR14074
```c++ //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===--------------------...
6ef89e4b-ce2a-476a-b28e-731b189431ba
{ "language": "C++" }
```c++ ``` Test for 'bad_array_length'; got left out of initial commit
```c++ //===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===---------------------------------...
1cf991f6-0e56-4391-8997-1a2742516c95
{ "language": "C++" }
```c++ ``` Implement useful function to compare double in order to prevent problems with precision.
```c++ #include <stdio.h> using namespace std; const double EPS = 1e-15; /* * Return * -1 if x < y * 0 if x == y * 1 if x > y */ int cmp (double x, double y){ return (x <= y + EPS) ? (x + EPS < y) ? -1 : 0 : 1; } int main(){ double d1 = 0.00000000000212; double d2 = 0.00000000000213; int...
29fa993b-39e0-4dd0-9da0-946c28f9dc68
{ "language": "C++" }
```c++ ``` Add an example using gsl::span<T>
```c++ // g++ -o span01 -Wall -Wextra -pedantic -std=c++14 -I GSL/include span01.cpp #include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <gsl/span> // See e.g. http://codexpert.ro/blog/2016/03/07/guidelines-support-library-review-spant/ template <typename T> void write_data_pass_by_...
167119d7-df7b-480f-9ed0-e8261f1b353f
{ "language": "C++" }
```c++ ``` Add nested loop example specimen 5
```c++ // A nested loop. #include <stdio.h> int main() { int n; scanf("%d", &n); int *A = new int[n]; int *B = new int[n]; for (int i = 0; i < n; ++i) { scanf("%d", &A[i]); } for (int i = 0; i < n; ++i) { scanf("%d", &B[i]); } int sum = 0; for (int i = 0; i < n; ++i) { for (int j = ...
da50f7d0-2f52-48aa-94ba-bd2c81f24b6c
{ "language": "C++" }
```c++ #include "server.h" using namespace SeaSocks; int main(int argc, const char* argv[]) { Server server; server.serve("src/web", 9090); return 0; } ``` Add a list of TODOs
```c++ #include "server.h" /* * TODOs: * * Add logging * * Connection class does *everything*. Work out better division of labour; server should do more, connection should just be connection stuff, handlers for data? * * sort out buffers and buffering * * work out what state to hang on to; handle multiple WS endp...
4635ca8e-970b-4eb4-b388-c1cf80510e6c
{ "language": "C++" }
```c++ ``` Add a RNN perf workbench
```c++ //======================================================================= // Copyright (c) 2014-2020 Baptiste Wicht // Distributed under the terms of the MIT License. // (See accompanying file LICENSE or copy at // http://opensource.org/licenses/MIT) //===========================================================...
3e87b0cd-20e8-4ccd-ae98-86cb665538cb
{ "language": "C++" }
```c++ ``` Add lexicographical compare with tie
```c++ // Lexicographic-compare // C++11 #include <tuple> class foo { public: foo(int n_, char c_, double d_) : n{n_}, c{c_}, d{d_} {} friend bool operator<(const foo& lh, const foo& rh) { return std::tie(lh.n, lh.c, lh.d) < std::tie(rh.n, rh.c, rh.d); } private: int n; char c; double d...
1822cc1f-5004-433a-b1f3-589018e8fb50
{ "language": "C++" }
```c++ ///////////////////////////////////////////////////////////////////////////// // This file is part of EasyRPG. // // EasyRPG is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the Lic...
```c++ ///////////////////////////////////////////////////////////////////////////// // This file is part of EasyRPG. // // EasyRPG is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the Lic...
7c0730f4-6a97-4371-8823-b5795bdfdc87
{ "language": "C++" }
```c++ ``` Add a simple example application
```c++ #include <cmath> #include <iostream> #include <random> #include <thread> #include "gflags/gflags.h" #include "glog/logging.h" #include "driver/engine.hpp" #include "lib/abstract_data_loader.hpp" #include "lib/labeled_sample.hpp" #include "lib/parser.hpp" using namespace csci5570; using Sample = double; usin...
9fd7d445-27e2-40db-809a-461834af5a1c
{ "language": "C++" }
```c++ ``` Add sample code file for Cmake tests
```c++ // A simple program that computes the square root of a number #include <stdio.h> #include <stdlib.h> #include <math.h> #include <iostream> #include <allegro5/allegro.h> #include "TutorialConfig.h" int main (int argc, char *argv[]) { if (argc < 2) { fprintf(stdout,"%s Version %d.%d\n", argv[0], ...
606812eb-cc02-4c83-a7a1-1ef31ab0eaaf
{ "language": "C++" }
```c++ ``` Implement a binary search on a sorted array
```c++ // // main.cpp // CPP // // Created by Mgen on 8/27/16. // Copyright © 2016 Mgen. All rights reserved. // #include <iostream> #include <vector> #include <algorithm> #include <set> using namespace std; // runs a binary search on a given array, returns the insert position of a given integer int findInsertPo...
2bbf970a-b4f4-47c6-a37a-74630523b62d
{ "language": "C++" }
```c++ ``` Add a test for PR3733.
```c++ struct x { x() : a(4) ; // expected-error {{expected '{'}} }; struct y { int a; y() : a(4) ; // expected-error {{expected '{'}} }; ```
f1838cfe-1493-4c03-921a-1d05ccdaccbc
{ "language": "C++" }
```c++ ``` Check if Every Row and Column Contains All Numbers
```c++ class Solution { public: bool checkValid(vector<vector<int>>& matrix) { for (int i = 0; i < matrix.size(); ++i) { std::vector<int> check(matrix.size()+1, 0); for (int j = 0; j < matrix[0].size(); ++j) { if (check[matrix[i][j]] == 1) return false; ...
e483a261-b27e-4d22-b7f8-f55319902423
{ "language": "C++" }
```c++ ``` Add solution for 226. Invert Binary Tree.
```c++ /** * [Link:] https://leetcode.com/problems/invert-binary-tree/ */ /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: TreeNode* invertTr...
42c89883-89d4-42ba-bfef-c704a3531332
{ "language": "C++" }
```c++ ``` Test implicit declaration of copy assignment operator with non-const argument
```c++ // RUN: %clang_cc1 -fsyntax-only -verify %s struct ConstCopy { ConstCopy(); ConstCopy &operator=(const ConstCopy&); }; struct NonConstCopy { NonConstCopy(); NonConstCopy &operator=(NonConstCopy&); }; struct VirtualInheritsNonConstCopy : virtual NonConstCopy { VirtualInheritsNonConstCopy(); Virtua...
4f205aaa-5e4d-4db7-aa7d-10e7f28c9ede
{ "language": "C++" }
```c++ ``` Add test program for breadth first search
```c++ #include<iostream> #include "bfs.h" // My implementation of breadth first search #include<vector> // tests Bfs traversal, distances and paths void testBfs(){ // edges std::vector<std::vector<int> > edges = { {1,5}, {3,5}, {2,4}, {1,4}, {5,7}, {7,6...
32834459-e587-4d56-87da-d97b5f87370d
{ "language": "C++" }
```c++ ``` Add algorithm to fing the len of longest common subsequenc..
```c++ #include <bits/stdc++.h> #define endl '\n' using namespace std; const int M_MAX = 20; // Máximo size del String 1 const int N_MAX = 20; // Máximo size del String 2 int m, n; // Size de Strings 1 y 2 string X; // String 1 string Y; // String 2 int memo[M_MAX + 1][N_MAX + 1]; int lcs (int m, int n) { for (int i ...
f78bb933-89ac-4828-83a0-df9b4fd517a4
{ "language": "C++" }
```c++ ``` Add Chapter 21, Try This 1
```c++ // Chapter 21, Try This 1: test two different definitions of the find algorithm #include "../lib_files/std_lib_facilities.h" //------------------------------------------------------------------------------ template<class In, class T> In find1(In first, In last, const T& val) { while (first!=last && *first...
06d02e1a-3ed6-4bcd-b831-33dfbdc500da
{ "language": "C++" }
```c++ ``` Add a scenario showing a kind of deadlock that is unsupported right now.
```c++ /** * This test checks whether we detect a deadlock arising from a parent thread * trying to join a child who requires a lock held by its parent in order to * finish. */ #include <d2mock.hpp> int main(int argc, char const* argv[]) { d2mock::mutex G; d2mock::thread t1([&] { G.lock(); ...
b6a1eecf-a01a-4cc2-9bc9-407796888f38
{ "language": "C++" }
```c++ ``` Test that static_assert is properly visited in liblcang
```c++ static_assert(2 + 2 == 4, "Simple maths"); // RUN: c-index-test -test-load-source all -fno-delayed-template-parsing -std=c++11 %s | FileCheck %s // CHECK: load-staticassert.cpp:2:1: StaticAssert=:2:1 (Definition) Extent=[2:1 - 2:42] // CHECK: load-staticassert.cpp:2:15: BinaryOperator= Extent=[2:15 - 2:25] // ...
3ea0b2a6-bb0b-483c-93fd-41d66c57025c
{ "language": "C++" }
```c++ ``` Remove nth element from the end of list.
```c++ /** * Remove Nth Node From End of List * Double pointer. * * cpselvis(cpselvis@gmail.com) * August 18th, 2016 */ #include<iostream> using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solution { public: ListNode* removeNthFromEnd(List...
a7c203f0-a710-4348-9c5f-625c56a4a1f3
{ "language": "C++" }
```c++ ``` Add stub exception handler backend for linux
```c++ /** ****************************************************************************** * Xenia : Xbox 360 Emulator Research Project * ****************************************************************************** * Copyright 2015 Ben Vanik. All rights reserved. ...
a8aaacbd-08f5-4bd9-bd11-2313aa488d34
{ "language": "C++" }
```c++ ``` Add Chapter 20, Try This 8
```c++ // Chapter 20, Try This 8: same as Try This 7, but with an array of int, a // vector<int> and a list<int>, with the value { 1, 2, 3, 4, 5 }. #include "../lib_files/std_lib_facilities.h" // requires size of array as it decays to a pointer void ai_func(const int ai[], int sz) { cout << "Number of elements in...
e8cbb91e-2abc-48a1-88bb-b90a782233cd
{ "language": "C++" }
```c++ ``` Implement queue using circular array
```c++ #include <iostream> using namespace std; struct Queue { int *array; int front, rear; int size; }; Queue* createQueue(int size) { Queue *queue = new Queue(); if (!queue) return NULL; queue->front = queue->rear = -1; queue->size = size; queue->array = new int[queue->size]; i...
0392a630-c2ed-4ba2-9a11-a4ee8f06648b
{ "language": "C++" }
```c++ ``` Add cc file with definition of tensorflow::gtl::nullopt.
```c++ /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable l...
03910a16-d974-4424-9b32-a9ed634fba9f
{ "language": "C++" }
```c++ ``` Add test case for crash reported in <rdar://problem/8236270> (which has since been fixed in trunk).
```c++ // RUN: c-index-test -test-load-source all %s 2>&1 | FileCheck %s // This test case previously just crashed the frontend. struct abc *P; int main( // CHECK: StructDecl=abc:5:8 Extent=[5:1 - 5:11] // CHECK: VarDecl=P:5:13 (Definition) Extent=[5:8 - 5:14] // CHECK: VarDecl=main:6:5 (Definition) Extent=[6:1 - 6:...
d1bc9ba2-f9c9-4f65-b867-3e4c9a2e5fd3
{ "language": "C++" }
```c++ ``` Add unit tests covering operator[] and insert
```c++ #include <gtest/gtest.h> #include "LRUCache.hxx" TEST(LRUCache, InsertPair) { LRUCache<int, std::string, 3> cache; auto pairResult = cache.insert(std::make_pair<int, std::string>(1, "1")); EXPECT_EQ(std::string("1"), pairResult.first->second); EXPECT_TRUE(pairResult.second); EXPECT_EQ(1, ca...
806904b7-6043-4754-a6e1-e1025754c76d
{ "language": "C++" }
```c++ ``` Add C++11 solution for Nov. 2013 Bronze Problem 1
```c++ #include <istream> #include <fstream> #include <set> #include <vector> #include <array> #include <algorithm> #include <iterator> using namespace std; int main() { ifstream cin("combo.in"); ofstream cout("combo.out"); int size; cin >> size; set<int> options; for (int i = 0; i < 2; i++) { int a, b, c; ...
90ab343a-1a1a-42ac-b1e9-706010c9de60
{ "language": "C++" }
```c++ ``` Add unit test for ControlTask
```c++ // Copyright (c) 2018 Chris Ohk, Youngjoong Kim, SeungHyun Jeon // We are making my contributions/submissions to this project solely in our // personal capacity and are not conveying any rights to any intellectual // property of any third parties. #include <Utils/TestUtils.hpp> #include "gtest/gtest.h" #inclu...
3796039e-994b-41ba-99d2-c3ea65a60484
{ "language": "C++" }
```c++ ``` Add entry file building glsl optimzier for emscripten
```c++ #include <stdio.h> #include <string.h> #include <stdlib.h> #include "glsl_optimizer.h" static glslopt_ctx* gContext = 0; #include <emscripten/val.h> #define str(str) std::string(str) static bool compileShader2(const char* originalShader, bool vertexShader) { if( !originalShader ) return false; const gl...
6e29429d-1541-4ff0-ae3e-1d7e399ceca6
{ "language": "C++" }
```c++ ``` Add fuzzing driver to classads HTCONDOR-814
```c++ #include "classad/classad_distribution.h" #include <string> #include <string.h> #include <sys/types.h> /* This is the driver for the classad fuzz tester. * Note this is intentionally not in the cmake file, it should not be built * by default. * * To use, compile all of classads with clang -fsanitize=fuzze...
194adbee-5507-4f5d-a9f1-5242ed34df87
{ "language": "C++" }
```c++ ``` Add example to read SDP3x using isr
```c++ #include <Arduino.h> #include "sdplib.h" #include "Wire.h" #define IRQ_PIN 4 SDPclass sdp; double diff_pressure, temperature; bool sdpFlag = false; // Interrupt routine void SDP_isr(void){ sdpFlag = true; } void setup(){ while(!Serial){ Serial.begin(115200); } pinMode(IRQ_PIN, ...
dccb5cfd-61f1-4c1a-8400-5fec1786577e
{ "language": "C++" }
```c++ ``` Add tests for 'InputArg' class
```c++ // Standard headers #include <memory> #include <iostream> // External headers #include "gmock/gmock.h" // Internal headers #include "InputArgs.hpp" // Alias using ::testing::DoubleNear; const double PI = 3.141592653589793238462643; class ASetOfInputArguments : public testing::Test { }; TEST_F(ASetOfInputAr...
186c4df9-10db-4c44-b8f9-25a5e54df625
{ "language": "C++" }
```c++ ``` Add missed test in r276090.
```c++ //===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===---------------------------------...
0f37689b-dcea-4d33-b2ce-a47195f8baf5
{ "language": "C++" }
```c++ ``` Add a test to cover the bug that was fixed recently where bool in memory is a byte, but a bool vector inside llvm is bitpacked so loading 8 bools would load a byte, not 8-bytes, if vectorized.
```c++ #include <stdio.h> #include <Halide.h> using namespace Halide; int main(int argc, char **argv) { Var x, y; Func pred("pred"); pred(x, y) = x < y; Func selector("selector"); selector(x, y) = select(pred(x, y), 1, 0); // Load a vector of 8 bools pred.compute_root(); selector.co...
8510003f-c237-4f9d-9849-46dff3c05fd2
{ "language": "C++" }
```c++ ``` Add new example: external interrupt on pin change
```c++ #include "board.h" #include <aery32/gpio.h> #include <aery32/delay.h> #include <aery32/intc.h> using namespace aery; void isrhandler(void) { gpio_toggle_pin(LED); delay_ms(100); /* Reduce glitch */ porta->ifrc = (1 << 0); /* Remember to clear the interrupt */ } int main(void) { init_board(); /* GPIO pin...
bce90138-5c15-400e-9484-b88cc7404564
{ "language": "C++" }
```c++ ``` Add executable allowing generation of the keyfile.
```c++ #include "condor_auth_passwd.h" #include "classad/classad.h" #include "classad/sink.h" #include "match_prefix.h" #include "CondorError.h" #include "condor_config.h" void print_usage(const char *argv0) { fprintf(stderr, "Usage: %s -identity USER@UID_DOMAIN [-token VALUE]\n\n" "Generates a derived key from th...
72f7efbd-307c-469e-ab75-65a26bc93d1f
{ "language": "C++" }
```c++ ``` Add a solution to problem 237: Delete Node in a Linked List.
```c++ // https://leetcode.com/problems/delete-node-in-a-linked-list/ // Since node given is not a tail. We could do a trick: copy the contents of // the next node, then connect to the next of next, delete the next node. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *ne...
223b4ffb-71e3-4bb8-8714-d22b88a3c6ae
{ "language": "C++" }
```c++ // Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/rand_util.h" #include <nacl/nacl_random.h> #include "base/basictypes.h" #include "base/logging.h" namespace { void GetRandom...
```c++ // Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/rand_util.h" #include <nacl/nacl_random.h> #include "base/basictypes.h" #include "base/logging.h" namespace { void GetRandom...
9bad9768-7cdc-405e-a098-8830f54f013f
{ "language": "C++" }
```c++ ``` Add test for a bad fold.
```c++ #include <stdio.h> #include "Halide.h" using namespace Halide; int main(int argc, char **argv) { Var x, y, c; Func f, g; f(x, y) = x; g(x, y) = f(x-1, y+1) + f(x, y-1); f.store_root().compute_at(g, y).fold_storage(y, 2); Image<int> im = g.realize(100, 1000); printf("Should have ...
e2213702-ab79-4b93-8e51-f5d2711cc4f3
{ "language": "C++" }
```c++ ``` Add the start of a new value test suite
```c++ /* Copyright © 2015 Jesse 'Jeaye' Wilkerson See licensing at: http://opensource.org/licenses/BSD-3-Clause File: test/src/value/main.cpp Author: Jesse 'Jeaye' Wilkerson */ #include <jeayeson/jeayeson.hpp> #include <jest/jest.hpp> #include "map/ctor.hpp" int main() { jest::worker const j{}; ret...
1f9ee95d-17c3-46c3-bb51-7181bfebf1b1
{ "language": "C++" }
```c++ ``` Add the solution to "Insertion Sort Advanced Analysis".
```c++ #include <iostream> using namespace std; long merge(long *a, long start, long mid, long end) { long sum = 0; long *temp = new long[end - start + 1]; long i = mid, j = end; long k = end - start; while (i >= start && j >= mid + 1) { if (a[i] > a[j]) { temp[k--] = a[i--]; sum += j - mid; } else { ...
0953141c-1781-4936-835b-31b9fbba49fd
{ "language": "C++" }
```c++ ``` Add solution for 128 Longest Consecutive Sequence
```c++ //128. Longest Consecutive Sequence /* *Given an unsorted array of integers, find the length of the longest consecutive elements sequence. * *For example, *Given [100, 4, 200, 1, 3, 2], *The longest consecutive elements sequence is [1, 2, 3, 4]. Return its length: 4. * *Your algorithm should run in O(n) complexi...
719a8720-5247-492b-b456-52ec3cebc7f4
{ "language": "C++" }
```c++ ``` Add code to delete node in linked list
```c++ #include<iostream> #include<cstdlib> using namespace std; class Node{ public: int data; Node *next; Node(){} Node(int d){ data=d; next=NULL; } Node *insertNode(Node *head, int d){ Node *np=new Node(d); Node *tmp=head; if(head==NULL) return np; else while(tmp->next) tmp=tmp->ne...
7119ca30-1ffb-4ae5-a75c-64f4369cbac6
{ "language": "C++" }
```c++ ``` Add missing C++ test bench driver
```c++ /* * Copyright 2019 The Project Oak Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicabl...
94e9d693-c815-4d62-9448-ea1a64bba803
{ "language": "C++" }
```c++ ``` Add a test for the full round trip through libclang and the plugin.
```c++ // RUN: c-index-test -test-load-source-reparse 2 all %s -Xclang -add-plugin -Xclang clang-include-fixer -fspell-checking -Xclang -plugin-arg-clang-include-fixer -Xclang -input=%p/Inputs/fake_yaml_db.yaml 2>&1 | FileCheck %s foo f; // CHECK: yamldb_plugin.cpp:3:1: error: unknown type name 'foo'; did you mean 'f...
622d63ac-780a-4bf3-81f8-fcfce8ff54d8
{ "language": "C++" }
```c++ ``` Add unit test for symmetry of OperatorChebyshevSmoother
```c++ // Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced // at the Lawrence Livermore National Laboratory. All Rights reserved. See files // LICENSE and NOTICE for details. LLNL-CODE-806117. // // This file is part of the MFEM library. For more information and source code // availability v...
ea774c99-af75-4362-a065-fb57e7969ed4
{ "language": "C++" }
```c++ ``` Add example that uses both gsl lite and span lite
```c++ #include "gsl/gsl-lite.hpp" #include "nonstd/span.hpp" int main() { const int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, }; { using gsl::span; span<const int> spn( arr ); } { using nonstd::span; span<const int> spn( arr ); } } // cl -nologo -EHsc -Dspan_FEATURE_MAKE_SPAN -I../include -I../../span-lit...
2ef28b64-27f8-411a-a00d-a87bb0fb5177
{ "language": "C++" }
```c++ /* * Part of HTTPP. * * Distributed under the 3-clause BSD licence (See LICENCE.TXT file at the * project root). * * Copyright (c) 2013 Thomas Sanchez. All rights reserved. * */ #include "httpp/http/Utils.hpp" #include <boost/algorithm/string.hpp> #include <iostream> namespace HTTPP { namespace HTTP ...
```c++ /* * Part of HTTPP. * * Distributed under the 3-clause BSD licence (See LICENCE.TXT file at the * project root). * * Copyright (c) 2013 Thomas Sanchez. All rights reserved. * */ #include "httpp/http/Utils.hpp" #include <boost/algorithm/string.hpp> #include <iostream> namespace HTTPP { namespace HTTP ...
a5394b20-e0a0-4a9d-917b-369739c39653
{ "language": "C++" }
```c++ ``` Add unit tests for parsable, but erroneous programs
```c++ #include <gtest/gtest.h> #include <platform.h> #include "util.h" /** Pony code that parses, but is erroneous. Typically type check errors and * things used is invalid contexts. * * We build all the way up to and including code gen and check that we do not * assert, segfault, etc but that the build fails a...
145f02d8-3ce4-4b3b-85dd-4059c0fd8f2c
{ "language": "C++" }
```c++ ``` Solve SRM 150, Div 2, Problem WidgetRepairs
```c++ #include <cassert> #include <vector> using namespace std; class WidgetRepairs { public: int days(vector<int> arrs, int numPerDay) { int ans = 0; int stack = 0; for (int d : arrs) { stack += d; if (stack > 0) { ans++; } stack -= numPerDay; if (stack < 0) { ...
5b3d8116-e587-406b-9072-bababffb98d7
{ "language": "C++" }
```c++ ``` Add forgotten to commit file.
```c++ //--------------------------------------------------------------------*- C++ -*- // CLING - the C++ LLVM-based InterpreterG :) // version: $Id$ // author: Baozeng Ding <sploving1@gmail.com> // author: Vassil Vassilev <vasil.georgiev.vasilev@cern.ch> //-----------------------------------------------------------...
5f9302bd-a183-482f-b641-da2db7cbf6fc
{ "language": "C++" }
```c++ ``` Add useful script for lower and upper bound over an array.
```c++ // lower_bound/upper_bound example #include <iostream> // cout #include <algorithm> // lower_bound, upper_bound, sort #include <vector> // vector using namespace std; int main () { int myints[] = {10,20,30,30,20,10,10,20}; vector<int> v(myints,myints+8); // 10 20 30 30 20 10 10 20 s...
a5835096-498e-4e68-987e-a83d37902f68
{ "language": "C++" }
```c++ ``` Test for shared allocations and thread blocks that depend on blockidx
```c++ #include <Halide.h> #include <stdio.h> using namespace Halide; int main(int argc, char **argv) { Func f, g; Var x; f(x) = x; g(x) = f(x) + f(2*x); g.gpu_tile(x, 16); f.compute_at(g, Var::gpu_blocks()).gpu_threads(x); // The amount of shared memory required varies with x Imag...
ac1ef30c-57ad-4220-8b68-4e4cf1a65209
{ "language": "C++" }
```c++ ``` Add basic string unit test
```c++ //--------------------------------------------------------------------------// /// Copyright (c) 2018 Milos Tosic. All Rights Reserved. /// /// License: http://www.opensource.org/licenses/BSD-2-Clause /// //--------------------------------------------------------------------------...
0ab87c84-b878-4c99-b69e-8d2fe1174021
{ "language": "C++" }
```c++ #include <xpcc/architecture/platform.hpp> #include <xpcc/debug/logger.hpp> using namespace xpcc::atmega; // Create a new UART object and configure it to a baudrate of 115200 Uart0 uart(115200); xpcc::IODeviceWrapper< Uart0 > loggerDevice(uart); // Set all four logger streams to use the UART xpcc::log::Logger...
```c++ #include <xpcc/architecture/platform.hpp> #include <xpcc/debug/logger.hpp> using namespace xpcc::atmega; typedef xpcc::avr::SystemClock clock; // Create a new UART object and configure it to a baudrate of 115200 Uart0 uart; xpcc::IODeviceWrapper< Uart0 > loggerDevice(uart); // Set all four logger streams to ...
27b3e30b-e075-48a0-8ef1-c1dba18e0824
{ "language": "C++" }
```c++ ``` Add file missed in previous commit.
```c++ // Copyright (c) 2015 The Gulden developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifdef __APPLE__ #include <TargetConditionals.h> #import "BRMerkleBlock.h" #endif #include "diff_common.h" #include "diff_del...