id int64 0 755k | file_name stringlengths 3 109 | file_path stringlengths 13 185 | content stringlengths 31 9.38M | size int64 31 9.38M | language stringclasses 1
value | extension stringclasses 11
values | total_lines int64 1 340k | avg_line_length float64 2.18 149k | max_line_length int64 7 2.22M | alphanum_fraction float64 0 1 | repo_name stringlengths 6 65 | repo_stars int64 100 47.3k | repo_forks int64 0 12k | repo_open_issues int64 0 3.4k | repo_license stringclasses 9
values | repo_extraction_date stringclasses 92
values | exact_duplicates_redpajama bool 2
classes | near_duplicates_redpajama bool 2
classes | exact_duplicates_githubcode bool 2
classes | exact_duplicates_stackv2 bool 1
class | exact_duplicates_stackv1 bool 2
classes | near_duplicates_githubcode bool 2
classes | near_duplicates_stackv1 bool 2
classes | near_duplicates_stackv2 bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
9,941 | n_queen_bitimp.cpp | OpenGenus_cosmos/code/backtracking/src/n_queen/n_queen_bitimp.cpp | #include <iostream>
// Part of Cosmos by OpenGenus Foundation
using namespace std;
int limit;
int N;
int counter;
void Backtracking(int position, int left, int right, int depth)
{
if (depth == N)
{
counter++;
return;
}
int currentPos = position | left | right;
int newPos;
while (... | 800 | C++ | .cpp | 32 | 20.28125 | 72 | 0.571056 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,942 | n_queen_backtracking.cpp | OpenGenus_cosmos/code/backtracking/src/n_queen/n_queen_backtracking.cpp | #include <iostream>
// Part of Cosmos by OpenGenus Foundation
using namespace std;
bool isSafe(char board[][100], int row, int column, int n)
{
//check that whole row should not have a queen
for (int i = 0; i < n; i++)
if (board[row][i] == 'Q')
return false;
//check that whole column ... | 2,014 | C++ | .cpp | 66 | 23.515152 | 94 | 0.489669 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,943 | n_queen_bitset.cpp | OpenGenus_cosmos/code/backtracking/src/n_queen/n_queen_bitset.cpp | ///GIVES TOTAL NUMBER OF POSSIBLE WAYS TO SOLVE N QUEEN PROBLEM USING BITSET
// Part of Cosmos by OpenGenus Foundation
#include <iostream>
#include <bitset>
using namespace std;
bitset<30> column, diag1, diag2;
void solveNQueen(int r, int n, int &ans)
{
if (r == n)
{
ans++;
return;
}
f... | 789 | C++ | .cpp | 32 | 19.375 | 76 | 0.511968 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,944 | sudoku_solve.cpp | OpenGenus_cosmos/code/backtracking/src/sudoku_solve/sudoku_solve.cpp | #include <iostream>
using namespace std;
/*
* Part of Cosmos by OpenGenus Foundation
*/
int n = 9;
bool isPossible(int mat[][9], int i, int j, int no)
{
///Row or col should not have no
for (int x = 0; x < n; x++)
if (mat[x][j] == no || mat[i][x] == no)
return false;
/// Subgrid sho... | 2,099 | C++ | .cpp | 83 | 18.807229 | 69 | 0.433849 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,947 | subset_sum.cpp | OpenGenus_cosmos/code/backtracking/src/subset_sum/subset_sum.cpp | /* Part of Cosmos by OpenGenus Foundation */
#include <iostream>
#include <vector>
using namespace std;
/*
* Generate all possible subset sums
* of array v that sum up to targetSum
*/
vector< vector<int>> generateSubsetSums(int v[], size_t size, int targetSum)
{
vector< vector<int>> solutions;
for (in... | 1,247 | C++ | .cpp | 43 | 22.302326 | 97 | 0.516807 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,951 | generate_parentheses.cpp | OpenGenus_cosmos/code/backtracking/src/generate_parentheses/generate_parentheses.cpp | /*
Input: n = 3
Output: ["((()))","(()())","(())()","()(())","()()()"]
Approach:
only add open paraenthesis if open < n
only add close parenthesis if close < open
stop- valid parenthesis if close == open == n
TC/SC - O(4^n)
*/
#include<bits/stdc++.h>
using namespace std;
vector<string> res;
void backtrack... | 985 | C++ | .cpp | 42 | 16.190476 | 56 | 0.48062 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,952 | partitions_of_number.cpp | OpenGenus_cosmos/code/backtracking/src/partitions_of_number/partitions_of_number.cpp | /// Part of Cosmos by OpenGenus Foundation
#include <stdio.h>
#include <vector>
void backtrack(int level);
void print_sol(int length);
std::vector<int> solution;
int N, S = 0;
int solsFound = 0;
int main()
{
scanf("%d", &N);
solution.reserve(N + 1);
solution[0] = 1;
backtrack(1);
return 0;
}
void ba... | 795 | C++ | .cpp | 37 | 16.918919 | 58 | 0.538259 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,954 | test_palindrome_check.cpp | OpenGenus_cosmos/code/unclassified/test/palindrome/palindrome_check/test_palindrome_check.cpp | #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cassert>
#include "../../../src/palindrome/palindrome_check/palindrome_check.cpp"
using namespace std;
using namespace palindrome_check;
// for test
struct MapValueEqual
{
bool operator()(std::pair<int, int> const &a, std::pair<int, i... | 6,229 | C++ | .cpp | 198 | 24.914141 | 88 | 0.529745 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,955 | test_spiral_print.cpp | OpenGenus_cosmos/code/unclassified/test/spiral_printing/test_spiral_print.cpp | #include "../../src/spiral_print/spiral_print.cpp"
#include <cassert>
int main()
{
using namespace std;
vector<vector<int>> vec;
// empty test
assert("" == spiralPrint(vec, 0, 0));
/* row test (even col)
* 1 2 3 4 5 6
* 7 8 9 10 11 12
* 13 14 15 16 17 18
* 19 20 21 22 2... | 1,721 | C++ | .cpp | 51 | 27.882353 | 89 | 0.512019 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,957 | majority_element_randomized.cpp | OpenGenus_cosmos/code/unclassified/src/majority_element/majority_element_randomized.cpp | #include <iostream>
#include <vector>
using namespace std;
int n;
vector<int> v;
// Randomized algorithm with expected runtime: O(n), and Space: O(1)
int majorityElement(vector<int>& nums) {
int pos = 0, n = nums.size(), freq;
while(1) {
freq = 0;
for(int x : nums)if(x == nums[pos])++freq;
... | 623 | C++ | .cpp | 27 | 17.962963 | 68 | 0.536256 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
9,958 | majority_element.cpp | OpenGenus_cosmos/code/unclassified/src/majority_element/majority_element.cpp | #include <iostream>
#include <vector>
using namespace std;
int n;
vector<int> v;
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
int tmp;
cin >> tmp;
v.push_back(tmp);
}
int m, i = 0;
for (int k = 0; k < n; k++)
{
int x = v[k];
if (!i)
... | 515 | C++ | .cpp | 31 | 10.193548 | 45 | 0.380252 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,960 | maximum_subarray_sum.cpp | OpenGenus_cosmos/code/unclassified/src/maximum_subarray_sum/maximum_subarray_sum.cpp | // Part of Cosmos by OpenGenus Foundation
// C++ implementation of simple algorithm to find
// Maximum Subarray Sum in a given array
// this implementation is done using Kadane's Algorithm which has a time complexity of O(n)
#include <iostream>
#include <vector>
#include <climits>
int maxSubarraySum(const std::vect... | 987 | C++ | .cpp | 36 | 22.611111 | 123 | 0.61945 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,961 | biggest_of_n_numbers2.cpp | OpenGenus_cosmos/code/unclassified/src/biggest_of_n_numbers/biggest_of_n_numbers2.cpp | #include <iostream>
using namespace std;
int main()
{
int n, max, tmp;
cout << "Enter numbers of elements : ";
cin >> n;
cout << "Enter numbers\n";
cin >> tmp;
max = tmp;
for (int i = 0; i < n - 1; i++)
{
cin >> tmp;
if (max < tmp)
max = tmp;
}
cout <... | 368 | C++ | .cpp | 19 | 14.526316 | 43 | 0.471264 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,962 | biggest_of_n_numbers.cpp | OpenGenus_cosmos/code/unclassified/src/biggest_of_n_numbers/biggest_of_n_numbers.cpp | // Part of cosmos from opengenus foundation
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
std::vector<int> arr;
std::cout << "Keep entering numbers (EOF to stop): ";
for (int num; std::cin >> num;)
arr.push_back(num);
sort(arr.begin(), arr.end());
std::cout << "... | 356 | C++ | .cpp | 13 | 23.923077 | 57 | 0.628319 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,963 | medianOfTwoSortedArrayOfDifferentLength.cpp | OpenGenus_cosmos/code/unclassified/src/median_two_sortedArrayOfDifferentLength/medianOfTwoSortedArrayOfDifferentLength.cpp | #include <bits/stdc++.h>
using namespace std;
double findMedian(int arr1[], int n1, int arr2[], int n2)
{
int lo = 0, hi = n1;
while (lo <= hi)
{
int cut1 = lo + (hi - lo) / 2;
int cut2 = (n1 + n2) / 2;
double l1 = cut1 == 0 ? INT_MIN : arr1[cut1 - 1];
double l2 = cut2 == 0... | 1,205 | C++ | .cpp | 53 | 15.09434 | 59 | 0.394599 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | true | true | true | false |
9,967 | palindrome_check.cpp | OpenGenus_cosmos/code/unclassified/src/palindrome/palindrome_check/palindrome_check.cpp | #include <iterator>
#include <type_traits>
#include <functional>
namespace palindrome_check {
template<typename _InputIter,
typename _ValueNotEqualTo
= std::not_equal_to<typename std::iterator_traits<_InputIter>::value_type>,
typename _IterLess = std::less<_InputIter>>
bool
isPalindromeR... | 1,541 | C++ | .cpp | 50 | 24.72 | 96 | 0.643098 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,968 | average.cpp | OpenGenus_cosmos/code/unclassified/src/average/average.cpp | /// Part of Cosmos by OpenGenus Foundation
/// Find of average of numbers in an array
/// Contributed by: Pranav Gupta (foobar98)
/// Modified by: Arnav Borborah (arnavb)
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
vector<int> elements;
cout <<... | 742 | C++ | .cpp | 25 | 26.16 | 89 | 0.668067 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,969 | arraytoset_iterator.cpp | OpenGenus_cosmos/code/unclassified/src/array_to_set/arraytoset_iterator.cpp | #include <iostream>
#include <set>
// This program converts an array to a set in C++ using iterators
// See the corresponding article here: https://iq.opengenus.org/convert-array-to-set-cpp/
int main()
{
int a[] = {4, 11, 5, 3, 1, 6};
std::set<int> s(std::begin(a), std::end(a));
for (int i : s) {
... | 388 | C++ | .cpp | 14 | 24.285714 | 89 | 0.586022 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
9,973 | paint_fill.cpp | OpenGenus_cosmos/code/unclassified/src/paint_fill/paint_fill.cpp | #include <iostream>
// Part of Cosmos by OpenGenus Foundation
using namespace std;
void print_matrix(char matrix[][100], int n, int m)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
cout << matrix[i][j];
cout << endl;
}
}
void paint_fill(int i, int j, char dot, ch... | 1,063 | C++ | .cpp | 37 | 23.864865 | 86 | 0.520197 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,975 | autobiographical_numbers.cpp | OpenGenus_cosmos/code/unclassified/src/autobiographical_numbers/autobiographical_numbers.cpp | // Part of OpenGenus Cosmos
#include <iostream>
#include <string>
#include <unordered_map>
int main()
{
std::string s2 = "22535320"; // Input string
// string s2 = "72100001000"; // Uncomment this for a "TRUE" answer example.
std::unordered_map<int, int> indexCounter;
std::uno... | 902 | C++ | .cpp | 30 | 23.833333 | 94 | 0.545984 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,976 | segregate_positive_negative.cpp | OpenGenus_cosmos/code/unclassified/src/segregate_positive_negative/segregate_positive_negative.cpp | // Segregate positive and negative numbers in an array
// Here, we try to place all negative numbers to the left
// and all positive elements to the right in O(n) time.
// We can achieve this using Sorting also. But that takes O(nlogn) time.
#include <iostream>
#include <cstdlib>
// Similar to the partition function i... | 1,333 | C++ | .cpp | 47 | 23.361702 | 72 | 0.563183 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,977 | optimized_fibonacci.cpp | OpenGenus_cosmos/code/unclassified/src/optimized_fibonacci/optimized_fibonacci.cpp | /* Fibonacci Series implemented using Memoization */
#include <iostream>
long long fibonacci (int n)
{
static long long fib[100] = {}; // initialises the array with all elements as 0
fib[1] = 0;
fib[2] = 1;
if (n == 1 || n == 2)
return fib[n];
else if (fib[n] != 0)
return fib[n];
... | 594 | C++ | .cpp | 25 | 19.12 | 83 | 0.530035 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,981 | lapindrome_checker.cpp | OpenGenus_cosmos/code/unclassified/src/lapindrom_checker/lapindrome_checker.cpp | // part of cosmos by opengenus foundation
#include <iostream>
#include <algorithm> // used for sort()
using namespace std;
bool isLapindrome(string str)
{
int mid = str.length() / 2;
int delim = (str.length() % 2) == 0 ? mid : mid + 1;
string first_half = str.substr(0, mid);
string second_half = st... | 755 | C++ | .cpp | 25 | 26.16 | 56 | 0.632964 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,982 | minsubarraysizewithdegree.cpp | OpenGenus_cosmos/code/unclassified/src/minimum_subarray_size_with_degree/minsubarraysizewithdegree.cpp | #include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
/* Part of Cosmos by OpenGenus Foundation */
using namespace std;
int minSubArraySizeWithDegree(const vector<int> nums)
{
unordered_map <int, int> m;
priority_queue<int> pq;
int best_degree = 1,
curr_best_degree = num... | 1,277 | C++ | .cpp | 60 | 14.866667 | 53 | 0.4725 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,984 | line_determinant_method.cpp | OpenGenus_cosmos/code/computational_geometry/src/2d_line_intersection/line_determinant_method.cpp | #include <iostream>
class TwoDimensionalLineIntersection
{
public:
bool determinantMethod();
void setCoordinatesOfLines(double x1_, double y1_, double x2_, double y2_, double x3_, double y3_, double x4_, double y4_);
void printIntersectionPoints();
private:
double x1_, y1_, x2_, y2_, x3_, y3_, x4_, y4... | 2,598 | C++ | .cpp | 77 | 28.233766 | 140 | 0.539563 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,985 | line_elemination_method.cpp | OpenGenus_cosmos/code/computational_geometry/src/2d_line_intersection/line_elemination_method.cpp | #include <iostream>
#include <vector>
class EliminationMethd2DLineIntersection
{
public:
void acceptTheCoordinates(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
void intersection1(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
... | 2,475 | C++ | .cpp | 70 | 30.9 | 149 | 0.607321 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,986 | 2d_line_intersection.cpp | OpenGenus_cosmos/code/computational_geometry/src/2d_line_intersection/2d_line_intersection.cpp | // computational geometry | 2D line intersecton | C++
// main.cpp
// forfun
//
// Created by Ivan Reinaldo Liyanto on 10/5/17.
// Copyright © 2017 Ivan Reinaldo Liyanto. All rights reserved.
// Path of Cosmos by OpenGenus Foundation
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
st... | 1,713 | C++ | .cpp | 59 | 25.372881 | 94 | 0.597687 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,987 | distance_between_points.cpp | OpenGenus_cosmos/code/computational_geometry/src/distance_between_points/distance_between_points.cpp | #include <iostream>
#include <cmath>
typedef std::pair<double, double> point;
#define x first
#define y second
double calcDistance (point a, point b)
{
return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}
int main ()
{
point a, b, c;
std::cin >> a.x >> a.y >> b.x >> b.y;
std::cout << calcDistance(a... | 328 | C++ | .cpp | 15 | 19.533333 | 55 | 0.61165 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,989 | 2d_separating_axis_test.cpp | OpenGenus_cosmos/code/computational_geometry/src/2d_separating_axis_test/2d_separating_axis_test.cpp | // computational geometry | Two convex polygon intersection 2d seperating axis test | C++
//Ivan Reinaldo Liyanto
// open genus - cosmos
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
struct vec2
{
double x, y;
vec2(double x, double y) : x(x), y(y)
{
}
friend vec2 opera... | 2,412 | C++ | .cpp | 75 | 25.866667 | 122 | 0.607573 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,990 | sutherland_hodgeman_clipping.cpp | OpenGenus_cosmos/code/computational_geometry/src/sutherland_hodgeman_clipping/sutherland_hodgeman_clipping.cpp | //
// main.cpp
// forfun
//
// Created by Ivan Reinaldo Liyanto on 10/5/17.
// Copyright © 2017 Ivan Reinaldo Liyanto. All rights reserved.
// Path of Cosmos by OpenGenus Foundation
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
struct coor2d
{
float x, y;
coor2d(float a, f... | 3,839 | C++ | .cpp | 134 | 23.552239 | 97 | 0.595432 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,991 | halfplane_intersection.cpp | OpenGenus_cosmos/code/computational_geometry/src/halfplane_intersection/halfplane_intersection.cpp | #include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const double INF = 1e9;
const double EPS = 1e-8;
class Point {
public:
double x, y;
Point()
{
}
Point(double x, double y) : x(x), y(y)
{
}
bool operator==(const Point &other) const
{
return abs(x -... | 4,099 | C++ | .cpp | 174 | 17.218391 | 80 | 0.48045 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,992 | quick_hull.cpp | OpenGenus_cosmos/code/computational_geometry/src/quick_hull/quick_hull.cpp | #include <vector>
#include <iostream>
#include <cmath>
using namespace std;
struct vec2
{
float x, y;
vec2(float x, float y) : x(x), y(y)
{
}
vec2()
{
}
};
vector<vec2> input;
vector<vec2> output;
float lineToPointSupport(vec2 l1, vec2 l2, vec2 p)
{
return abs ((p.y - l1.y) * (l2.x -... | 2,173 | C++ | .cpp | 86 | 20.325581 | 94 | 0.54778 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,995 | jarvis_march.cpp | OpenGenus_cosmos/code/computational_geometry/src/jarvis_march/jarvis_march.cpp | #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
struct Point
{
int x;
int y;
int pos;
Point(int x, int y, int p)
{
this->x = x;
this->y = y;
this->pos = p;
}
};
int orientation(Point p, Point q, Point r)
{
int cross = (q.y - p.y) * (r.x ... | 1,748 | C++ | .cpp | 69 | 19.985507 | 79 | 0.514097 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
9,999 | axis_aligned_bounding_box_collision.cpp | OpenGenus_cosmos/code/computational_geometry/src/axis_aligned_bounding_box_collision/axis_aligned_bounding_box_collision.cpp | #include <iostream>
// Part of Cosmos by OpenGenus Foundation
struct Vector
{
int x;
int y;
};
struct Shape
{
Vector center;
int width;
int height;
};
bool checkAABBCollision(Shape &a, Shape &b)
{
// change '<' to '<=' if you want to include edge touching as a collision
return (abs(a.cente... | 907 | C++ | .cpp | 34 | 22.882353 | 77 | 0.557225 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,000 | dda_line.cpp | OpenGenus_cosmos/code/computational_geometry/src/dda_line/dda_line.cpp | #include <iostream>
class DDALineDrawingAlgorithm
{
public:
void ddaLineDrawing();
void getCoordinates();
private:
int x1_, x2_, y1_, y2_;
};
void DDALineDrawingAlgorithm::ddaLineDrawing()
{
//calculating range for line between start and end point
int dx = x2_ - x1_;
int d... | 1,630 | C++ | .cpp | 53 | 25.320755 | 84 | 0.59373 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,001 | cohen_sutherland_lineclip.cpp | OpenGenus_cosmos/code/computational_geometry/src/cohen_sutherland_lineclip/cohen_sutherland_lineclip.cpp | #include <iostream>
class CohenSutherLandAlgo
{
public:
CohenSutherLandAlgo() : x1_(0.0), x2_(0.0), y1_(0.0), y2_(0.0) { }
void setCoordinates(double x1, double y1, double x2, double y2);
void setClippingRectangle(double x_max, double y_max, double x_min, double y_min);
int generateCode(double ... | 5,045 | C++ | .cpp | 153 | 24.320261 | 102 | 0.49456 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,004 | area_of_triangle_herons_formula.cpp | OpenGenus_cosmos/code/computational_geometry/src/area_of_triangle/area_of_triangle_herons_formula.cpp | #include <iostream>
#include <cmath>
class AreaOfTriangle
{
public:
AreaOfTriangle(double a, double b, double c) : a_(a), b_(b), c_(c) {}
double calculateArea();
private:
double a_, b_, c_;
};
double AreaOfTriangle::calculateArea()
{
/*
* As magnitude of length of sides must be positive.
... | 1,198 | C++ | .cpp | 37 | 28.162162 | 90 | 0.566724 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,005 | area_of_polygon.cpp | OpenGenus_cosmos/code/computational_geometry/src/area_of_polygon/area_of_polygon.cpp | #include <iostream>
typedef std::pair<double, double> point;
const int size = 100000;
point points[size];
#define x first
#define y second
double calcArea(point a, point b, point c)
{
return abs( (a.first - b.first) * (c.second - b.second) - (a.second - b.second) *
(c.first - b.first) ) / 2;
}
... | 595 | C++ | .cpp | 22 | 22.909091 | 85 | 0.570922 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,006 | bresenham_circle.cpp | OpenGenus_cosmos/code/computational_geometry/src/bresenham_circle/bresenham_circle.cpp | #include <iostream>
#include "graphics.h"
class BresenhamCircle
{
public:
BresenhamCircle(int radius_) : radius_(radius_) { }
void getRadiusCenter();
void drawBresenhamCircle();
void displayBresenhmCircle(int xc_, int yc_, int x, int y);
private:
int radius_;
int xc_;
... | 2,061 | C++ | .cpp | 70 | 23.385714 | 90 | 0.595323 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,008 | quickselect.cpp | OpenGenus_cosmos/code/selection_algorithms/src/quickselect.cpp | // This algorithm is similar to quicksort because it
// chooses an element as a pivot and partitions the
// data into two based on the pivot. However, unlike
// quicksort, quickselect only recurses into one side
// - the side with the element it is searching for.
#include <iostream>
#include <vector>
#include <cmath>
#... | 1,652 | C++ | .cpp | 53 | 27.132075 | 98 | 0.634253 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,010 | ceil_of_element_in_sorted_array.cpp | OpenGenus_cosmos/code/algorithm_applications/src/binary_search/ceil_of_element/ceil_of_element_in_sorted_array.cpp | #include<bits/stdc++.h>
using namespace std;
int solve(int arr[],int n, int ele){
int ans=-1;
int low=0;
int high=n-1;
while(low<=high){
int mid=low+(high-low)/2;
if(ele==arr[mid]){
return ele;
}
else if(ele>arr[mid]){
ans=mid;
high=mid-1;
}
else{
low=mid+1;... | 566 | C++ | .cpp | 34 | 12.441176 | 44 | 0.526316 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,012 | firstAndLastPosInSortedArray.cpp | OpenGenus_cosmos/code/algorithm_applications/src/binary_search/first_and_last_position_in_sorted_array/firstAndLastPosInSortedArray.cpp | #include <bits/stdc++.h>
using namespace std;
int first(int arr[], int x, int n)
{
int low = 0, high = n - 1, res = -1;
while (low <= high)
{
int mid = (low + high) / 2;
if (arr[mid] > x)
high = mid - 1;
else if (arr[mid] < x)
low = mid + 1;
else
... | 1,053 | C++ | .cpp | 56 | 12.232143 | 67 | 0.380665 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,014 | test_naive_pattern_search.cpp | OpenGenus_cosmos/code/string_algorithms/test/test_naive_pattern_search.cpp | /**
* @file test_naive_pattern_search.cpp
* @author zafar hussain (zafar_hussain2000@hotmail.com)
* @brief test naive_pattern_search.cpp
* @version 0.1
* @date 2022-10-16
*
* @copyright Copyright (c) 2022
*
*/
#include <assert.h>
#include "./../src/naive_pattern_search/naive_pattern_search.cpp"
int main() {
... | 715 | C++ | .cpp | 23 | 28.695652 | 65 | 0.631732 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,015 | kasai_algorithm.cpp | OpenGenus_cosmos/code/string_algorithms/src/kasai_algorithm/kasai_algorithm.cpp | /*
*
* Kasai Algorithm
* https://www.geeksforgeeks.org/%C2%AD%C2%ADkasais-algorithm-for-construction-of-lcp-array-from-suffix-array/
*
*/
#include <iostream>
#include <vector>
#include <string>
std::vector<int> kasaiAlgorithm(std::string s, std::vector<int> suffix_array)
{
size_t m = 0;
std::vector<int> L... | 1,141 | C++ | .cpp | 40 | 23.35 | 110 | 0.527854 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,019 | morsecode.cpp | OpenGenus_cosmos/code/string_algorithms/src/morse_code/morsecode.cpp | #include <iostream>
#include <string>
#include <vector>
std::pair<char, std::string> pairing(char alpha, std::string morse_code);
std::string finder(const std::vector<std::pair<char, std::string>> &mp, std::string value);
std::string wordToMorse(const std::vector<std::pair<char, std::string>> &mp, std::string input);
... | 3,979 | C++ | .cpp | 115 | 28.495652 | 101 | 0.525797 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,020 | string_addition.cpp | OpenGenus_cosmos/code/string_algorithms/src/arithmetic_on_large_numbers/string_addition.cpp | #include <string>
#include <iostream>
#include <cassert>
std::string strAdd(std::string s, std::string r)
{
int re = 0;
std::string sum;
// precondition for empty strings
assert(s.length() > 0 && r.length() > 0);
if (r.length() < s.length())
r.insert(r.begin(), s.length() - r.length(), '0... | 939 | C++ | .cpp | 34 | 22.852941 | 61 | 0.511654 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,025 | trie_pattern_search.cpp | OpenGenus_cosmos/code/string_algorithms/src/trie_pattern_search/trie_pattern_search.cpp | #include <iostream>
#include <string>
#include <stdlib.h>
#include <vector>
#define alphas 26
using namespace std;
typedef struct Node
{
Node *child[alphas];
int leaf;
}trieNode;
trieNode* getNode()
{
trieNode *t = new trieNode;
if (t)
{
for (int i = 0; i < alphas; i++)
t->chi... | 2,098 | C++ | .cpp | 103 | 14.330097 | 59 | 0.481351 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,027 | pw_checker.cpp | OpenGenus_cosmos/code/string_algorithms/src/password_strength_checker/pw_checker.cpp | // C++ program for check password strength
//
// main.cpp
// pw_checker
//
#include <iostream>
#include <string>
using namespace std;
int main()
{
// criteria
bool has_upper_letter = false;
bool has_lower_letter = false;
bool has_digits_letter = false;
bool has_approved_length = false;
bo... | 1,767 | C++ | .cpp | 55 | 23.472727 | 97 | 0.549853 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,030 | z_algorithm.cpp | OpenGenus_cosmos/code/string_algorithms/src/z_algorithm/z_algorithm.cpp | #include <string>
#include <iostream>
void Zalgo(std::string s, std::string pattern)
{
using namespace std;
string k = pattern + "&" + s;
size_t Z[k.length()]; //Z-array for storing the length of the longest substring
//starting from s[i] which is also a prefix of s[0..n-1]
s... | 1,345 | C++ | .cpp | 51 | 17.980392 | 83 | 0.42835 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,033 | pangram.cpp | OpenGenus_cosmos/code/string_algorithms/src/pangram_checker/pangram.cpp | /*
* pangram.cpp
* by Charles (@c650)
*
* Part of Cosmos by OpenGenus Foundation
*/
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
/*
* Return whether or not str is a pangram, in O(n) time.
*/
static bool is_pangram(const std::string& str);
static void test_pang... | 2,027 | C++ | .cpp | 57 | 31.140351 | 102 | 0.634596 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,035 | naive_pattern_search.cpp | OpenGenus_cosmos/code/string_algorithms/src/naive_pattern_search/naive_pattern_search.cpp | // # Part of Cosmos by OpenGenus Foundation
#include <cstddef>
#include <cstring>
int search(const char *pattern, const char *text) {
/**
* @brief Searches for the given pattern in the provided text,
*
*
* @param pat Pattern to search for
* @param txt Text to search in
*
* @returns [int] positi... | 1,161 | C++ | .cpp | 33 | 31.151515 | 80 | 0.593918 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,036 | remove_dups.cpp | OpenGenus_cosmos/code/string_algorithms/src/remove_dups/remove_dups.cpp | #include <iostream>
//Part of Cosmos by OpenGenus Foundation
void removeDups(std::string &str)
{
std::string resStr;
resStr.push_back(str.front());
for (std::string::iterator it = str.begin() + 1; it != str.end(); ++it)
if (*it != resStr.back())
resStr.push_back(*it);
std::swap(str... | 545 | C++ | .cpp | 20 | 23.1 | 75 | 0.599617 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,037 | aho_corasick_algorithm2.cpp | OpenGenus_cosmos/code/string_algorithms/src/aho_corasick_algorithm/aho_corasick_algorithm2.cpp | #include <vector>
#include <fstream>
#include <queue>
using namespace std;
const int MAXN = 1000005;
char word[MAXN];
int n;
struct trie_node
{
int nr;
trie_node *children[26];
trie_node *fail;
vector<trie_node* >out;
trie_node()
{
nr = 0;
for (int i = 0; i < 26; i++)
... | 2,166 | C++ | .cpp | 93 | 15.989247 | 64 | 0.453835 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,040 | randomized_quicksort.cpp | OpenGenus_cosmos/code/randomized_algorithms/src/randomized_quick_sort/randomized_quicksort.cpp | // implementation of quicksort using randomization
// by shobhit(dragon540)
#include <algorithm>
#include <ctime>
#include <iostream>
#include <vector>
void quicksort(std::vector<int> &vect, int low, int high);
int part(std::vector<int> &vect, int low, int high);
int main()
{
srand(time(NULL));
std::vector<i... | 1,234 | C++ | .cpp | 44 | 23.454545 | 70 | 0.575424 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,041 | random_number_selection_from_a_stream.cpp | OpenGenus_cosmos/code/randomized_algorithms/src/random_from_stream/random_number_selection_from_a_stream.cpp | // Randomly select a number from stream of numbers.
// A function to randomly select a item from stream[0], stream[1], .. stream[i-1]
#include <random>
#include <iostream>
using namespace std;
int selectRandom(int x)
{
static int res; // The resultant random number
static int count = 0; //Count of numbers v... | 1,106 | C++ | .cpp | 37 | 24.675676 | 82 | 0.599624 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,042 | shuffle_an_array.cpp | OpenGenus_cosmos/code/randomized_algorithms/src/shuffle_an_array/shuffle_an_array.cpp | #include <array>
#include <iostream>
#include <iterator>
#include <random>
// Part of Cosmos by OpenGenus Foundation
template<class It, class RNG>
void shuffle_an_array(It first, It last, RNG &&rng)
{
std::uniform_int_distribution<> dist;
using ptype = std::uniform_int_distribution<>::param_type;
using std... | 755 | C++ | .cpp | 23 | 29.391304 | 71 | 0.608516 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,043 | kth_smallest_element_algorithm.cpp | OpenGenus_cosmos/code/randomized_algorithms/src/kth_smallest_element_algorithm/kth_smallest_element_algorithm.cpp | #include <iostream>
#include <climits>
#include <cstdlib>
using namespace std;
// Part of Cosmos by OpenGenus Foundation
int randomPartition(int arr[], int l, int r);
// QuickSort based method. ASSUMPTION: ELEMENTS IN ARR[] ARE DISTINCT
int kthSmallest(int arr[], int l, int r, int k)
{
// If k is smaller than num... | 2,211 | C++ | .cpp | 72 | 25.944444 | 79 | 0.589756 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,045 | reservoir_sampling.cpp | OpenGenus_cosmos/code/randomized_algorithms/src/reservoir_sampling/reservoir_sampling.cpp | // An efficient program to randomly select k items from a stream of n items
// Part of Cosmos by OpenGenus Foundation
#include <iostream>
using namespace std;
void printArray(int stream[], int n)
{
for (int i = 0; i < n; i++)
printf("%d ", stream[i]);
printf("\n");
}
// A function to randomly select k... | 1,447 | C++ | .cpp | 48 | 25.395833 | 75 | 0.608914 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,046 | the_maximum_subarray.cpp | OpenGenus_cosmos/code/online_challenges/src/hackerrank/the_maximum_subarray/the_maximum_subarray.cpp | #include <iostream>
#include <vector>
#include <algorithm>
int main()
{
int t; //t is the number of test case
std::cin >> t;
while (t--) {
int n; //n is the size of input array
int sum, ans, ans1;
sum = ans = ans1 = 0;
int flag = 0;
std::cin >> n;
std... | 1,009 | C++ | .cpp | 38 | 17.342105 | 65 | 0.369678 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,047 | 3D_surface_area.cpp | OpenGenus_cosmos/code/online_challenges/src/hackerrank/3D_aurface_area/3D_surface_area.cpp | #include <iostream>
int main()
{
int h, w;
int a[110][110];
std::cin >> h >> w;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j)
std::cin >> a[i][j];
}
int sum = 0;
for (int i = 0; i < h; ++i) {
if (i == 0) {
for (int j = 0; j < w; ++j) {
... | 1,430 | C++ | .cpp | 50 | 15.16 | 59 | 0.240203 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,048 | encryption.cpp | OpenGenus_cosmos/code/online_challenges/src/hackerrank/encryption/encryption.cpp | #include <cmath>
#include <iostream>
int main()
{
std::string s;
std::cin >> s;
int r, c;
int l = s.size();
r = floor(sqrt(l));
c = ceil(sqrt(l));
for (int i = 0; i < c; ++i) {
for (int j = i; j < l; j = j + c)
std::cout << s[j];
std::cout << "\n";
}
}
| 317 | C++ | .cpp | 16 | 14.8125 | 41 | 0.427609 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,049 | array_manipulation.cpp | OpenGenus_cosmos/code/online_challenges/src/hackerrank/array_manipulation/array_manipulation.cpp | #include <iostream>
#include <vector>
#include <algorithm>
int main()
{
int n;
int m;
int a;
int b;
int k;
std::cin >> n >> m;
std::vector<std::pair<int, int> > v;
for (int i = 0; i < m; ++i) {
std::cin >> a >> b >> k;
v.push_back(std::make_pair(a, k));
v.push_... | 576 | C++ | .cpp | 26 | 17.076923 | 51 | 0.457721 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,054 | almost_sorted.cpp | OpenGenus_cosmos/code/online_challenges/src/hackerrank/almost_sorted/almost_sorted.cpp | #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
int main()
{
int n = 0;
int p = 0;
int s, l;
s = l = 0;
int t = 0;
std::cin >> n;
std::vector<int> a(n);
std::vector<int> b(n);
for (int i; i < n; ++i) {
std::cin >> a[i];
b... | 1,100 | C++ | .cpp | 51 | 13.45098 | 57 | 0.325 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,055 | CHDIGER.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/CHDIGER/CHDIGER.cpp | #include <iostream>
#include <algorithm>
#include <list>
#include <stack>
#include <string>
int main ()
{
int t;
std::cin >> t;
while (t--)
{
std::string n;
int d;
std::cin >> n >> d;
std::list<char>ans;
std::stack<char>st;
for (int i = 0; i < n.size();... | 899 | C++ | .cpp | 43 | 12.44186 | 54 | 0.363636 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,056 | LAZERTST.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/LAZERTST/LAZERTST.cpp | #include<iostream>
using namespace std;
typedef long long ll;
void solve()
{
ll n,m,k,q;
cin>>n>>m>>k>>q;
vector<pair<int,int>> qs(q);
vector<ll> ans(q,0);
for (int i = 0; i < q; i++)
{
cin>>qs[i].first>>qs[i].second;
}
if(k==3)
{
cout<<2<<' ';
for (int i =... | 1,180 | C++ | .cpp | 66 | 10.257576 | 78 | 0.336036 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,057 | hard_cash.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/CASH/hard_cash.cpp | #include <iostream>
int main() {
int t;
std::cin >> t;
while (t--) {
int n, k, x, sum = 0;
std::cin >> n >> k;
for (int i = 0; i < n; ++i) {
std::cin >> x;
sum += x;
}
sum %= k;
std::cout << sum << "\n";
}
}
| 297 | C++ | .cpp | 15 | 12.866667 | 37 | 0.33452 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,058 | JOHNY.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/JOHNY/JOHNY.cpp | #include <iostream>
int main() {
int t;
std::cin >> t;
while (t--) {
int n;
std::cin >> n;
int a[100];
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
}
int k;
std::cin >> k;
int ans = 0;
for (int... | 451 | C++ | .cpp | 21 | 12.809524 | 37 | 0.329177 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,059 | JAIN.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/JAIN/JAIN.cpp | #include <iostream>
#include <algorithm>
#include <list>
#include <stack>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <utility>
std::map<char,int>g_mp;
void build ()
{
g_mp.insert(std::make_pair('a',16));
g_mp.insert(std::make_pair('e',8));
g_mp.insert(std::make_pair('i',4))... | 1,536 | C++ | .cpp | 63 | 16.222222 | 68 | 0.412047 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,060 | CHNUM.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/CHNUM/CHNUM.cpp | #include <iostream>
#include <algorithm>
#include <list>
#include <stack>
#include <string>
int main ()
{
int t;
std::cin >> t;
while (t--)
{
int n;
std::cin >> n;
int a;
int cnt_ps = 0, cnt_nt = 0;
for (int i = 0; i < n; ++i)
{
std::cin >> a... | 638 | C++ | .cpp | 30 | 14.066667 | 89 | 0.406977 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,061 | coins.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/COINS/coins.cpp | #include <iostream>
#include <unordered_map>
#define lli long long int
std::unordered_map<lli, lli> mpp;
lli check(lli n)
{
if (n == 0) {
mpp[0] = 0;
return 0;
}
if (mpp[n] != 0)
return mpp[n];
else {
mpp[n] = check(n / 2) + check(n / 3) + check(n / 4);
mpp[n] =... | 514 | C++ | .cpp | 26 | 14.923077 | 60 | 0.477273 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,062 | CHFING.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/CHFING/CHFING.cpp | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FLASH ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
int main()
{
int t;
long long k,n,ans,x,y,z,a;
cin >> t;
while(t--)
{
ans = x = y = z = a = 0;
cin >> n >> k;
... | 772 | C++ | .cpp | 36 | 14.222222 | 69 | 0.401138 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,063 | snug_fit.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/SNUG_FIT/snug_fit.cpp | #include <algorithm>
#include <iostream>
#include <vector>
int main() {
int t;
std::cin >> t;
while (t--) {
int n, i, sum = 0;
std::cin >> n;
std::vector<int> a(n), b(n);
for (i = 0; i < n; ++i) {
std::cin >> a[i];
}
for (i = 0; i < n; ++i) {
... | 561 | C++ | .cpp | 24 | 16.166667 | 40 | 0.369403 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,064 | SLAB.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/SLAB/SLAB.cpp | // Part of Cosmos by OpenGenus
#include <iostream>
using namespace std;
int main ()
{
int t;
cin >> t;
while (t --)
{
long long int total, net, tax;
cin >> total;
if (total <= 250000)
{
net = total;
}
else if ((250000 < total) && (t... | 1,671 | C++ | .cpp | 49 | 24.44898 | 183 | 0.462387 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,065 | eid2.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/EID2/eid2.cpp | #include <algorithm>
#include <iostream>
#include <vector>
bool istrue(std::vector<int> a, std::vector<int> c) {
std::pair<int, int> pairt[3];
bool x = true;
int i;
for (i = 0; i < 3; ++i) {
pairt[i].first = a[i];
pairt[i].second = c[i];
}
std::sort(pairt, pairt + 3);
for (i... | 1,275 | C++ | .cpp | 52 | 16.192308 | 57 | 0.39198 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,066 | NBONACCI.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/NBONACCI/NBONACCI.cpp | #include <iostream>
#include <algorithm>
int main ()
{
int n,q;
std::cin >> n >> q;
int a[n];
for (int i = 0; i < n; ++i)
{
std::cin>>a[i];
}
int x = 0;
int xors[n] = {0};
for (int i = 0; i < n; ++i)
{
x = x ^ a[i];
xors[i] = x;
}
while (q--)
... | 521 | C++ | .cpp | 29 | 12.034483 | 47 | 0.36701 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,067 | HILLJUMP.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/HILLJUMP/HILLJUMP.cpp | #include<iostream>
using namespace std;
void jump(int[], int);
void inc(int[], int);
int main()
{
std::ios::sync_with_stdio(false);
//int j;for(j=0;j<100;j++)printf("1 ");
int n, q; cin>>n>>q;
int arr[n]; arr[0]=0;
int i; for(i=0;i<n;i++)
{
int temp; cin>>temp; arr[i]+=temp; arr[i+1]=-temp;
}
while(q--)
... | 812 | C++ | .cpp | 47 | 15.425532 | 52 | 0.596026 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,068 | MEETUP.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/MEETUP/MEETUP.cpp | #include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef long doubl... | 3,502 | C++ | .cpp | 237 | 12.101266 | 49 | 0.528941 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,069 | CHEFING.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/CHEFING/CHEFING.cpp | #include<bits/stdc++.h>
using namespace std;
int main()
{
int t,n,cnt,i,j;
string s;
cin >> t;
while(t--)
{
cnt = 0;
cin >> n;
int hash[n][26] = {0};
for(i = 0 ; i < n ; i++)
{
cin >> s;
for(j = 0 ; j < s.length() ; j++)
{
hash[i][s[... | 624 | C++ | .cpp | 35 | 9.971429 | 42 | 0.309353 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,070 | STRWN.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/STRWN/STRWN.cpp | #include <iostream>
#define ll long long
#define ld long double
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ff first
#define ss second
#define maxn 1000000007
#define PI 3.14159265358979323846
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//... | 983 | C++ | .cpp | 56 | 12.482143 | 37 | 0.485931 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,071 | BACREP.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/BACREP/BACREP.cpp | #include <iostream>
using namespace std;
#define ll long long
#define dd double
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define fi first
#define se second
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
ll mod=1000000007;
const ll N=500... | 2,195 | C++ | .cpp | 119 | 11.983193 | 69 | 0.442177 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,072 | PBATTLE.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/P-BATTLE/PBATTLE.cpp | // Question link : https://www.codechef.com/submit/PBATTLE
//Author - Vishwas Kapoor
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve(){
int n;
cin>>n;
vector<pair<int,int>> pg; // pokemon ground
fl(n){
int x;
... | 760 | C++ | .cpp | 40 | 16.525 | 68 | 0.628205 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,073 | NEWSCH.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/NEWSCH/NEWSCH.cpp | #include <iostream>
#include <cstring>
using namespace std;
#define MOD 1000000007
uint64_t modmul(const uint64_t x, const uint64_t y)
{
if (x > (1 << 30) && y > (1 << 30))
return ((x >> 30)*((y << 30) % MOD) + y*(x & ((1 << 30) - 1))) % MOD;
uint64_t z = x*y;
if (z >= MOD)
z %= MOD;
return z;
}
uint64_t m... | 750 | C++ | .cpp | 44 | 14.704545 | 71 | 0.547278 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,074 | Mathces.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/MATCHES/Mathces.cpp | #include <iostream>
#include <vector>
int main() {
std::vector<int> m = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int t;
std::cin >> t;
while (t--) {
long long int a, b, sum = 0;
std::cin >> a >> b;
a += b;
while (a > 0) {
sum += m[a % 10];
a /= 10;
... | 365 | C++ | .cpp | 17 | 15 | 56 | 0.37464 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,075 | EGGFREE.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/EGGFREE/EGGFREE.cpp | #include <iostream>
using namespace std;
int tt,n,m,old,it,i,j,k,x[222],y[222],u[222];
bool g[222][222],q;
char r[222];
int main()
{
scanf("%d",&tt);
while (tt--)
{
scanf("%d%d",&n,&m);
memset(u,0,sizeof(u));
memset(g,0,sizeof(g));
memset(r,0,sizeof(r));
for (i=0; i<m; i++)
{
s... | 981 | C++ | .cpp | 47 | 15.106383 | 80 | 0.3942 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,076 | COVID19.cpp | OpenGenus_cosmos/code/online_challenges/src/codechef/COVID19/COVID19.cpp | #include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
std::vector<int> x(n);
for(int &i:x)
cin>>i;
int smallest=10,largest=0,infected=1;
for(int i=1;i<n;i++)
{
if(x[i]-x[i-1]<=2)
infected++;
else
{
largest=max(largest,infected);
... | 565 | C++ | .cpp | 35 | 13.028571 | 39 | 0.620952 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,078 | median_of_two_sorted_arrays.cpp | OpenGenus_cosmos/code/online_challenges/src/leetcode/median_of_two_sorted_arrays/median_of_two_sorted_arrays.cpp | class Solution
{
public:
double findMedianSortedArrays(vector<int> &nums1, vector<int> &nums2)
{
int i = 0, j = 0;
double m;
vector<int> v;
while (i < nums1.size() && j < nums2.size())
{
if (nums1[i] < nums2[j])
{
v.push_back(nums1[... | 959 | C++ | .cpp | 40 | 14.275 | 81 | 0.357998 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,079 | arranging_coins.cpp | OpenGenus_cosmos/code/online_challenges/src/leetcode/Arranging_coins/arranging_coins.cpp | #include<bits/stdc++.h>
using namespace std;
class Solution {
public:
bool possibol(int n, long long row){
long sum = (row*(row+1))/2;
return n>=sum;
}
int arrangeCoins(int n) {
int start=0,end=n,answer=0;
while(start<=end){
int mid=start+(end-start)/2;
... | 583 | C++ | .cpp | 26 | 14.730769 | 46 | 0.491833 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,080 | maximumsubarray.cpp | OpenGenus_cosmos/code/online_challenges/src/leetcode/maximum_subarray/maximumsubarray.cpp | //In this corrected code, we compare max_ending + nums[i] with nums[i] to determine if it's beneficial to extend the current subarray or start a new one. This way, the code correctly calculates the maximum subarray sum.
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int len = nums.size();
... | 762 | C++ | .cpp | 20 | 27.3 | 219 | 0.542254 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,081 | remove_duplicates_from_sorted_list_ii.cpp | OpenGenus_cosmos/code/online_challenges/src/leetcode/remove_duplicates_from_sorted_list_ii/remove_duplicates_from_sorted_list_ii.cpp | /*
link to problem:https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/
difficulty level: Medium
approach:
maintained a previous,current and next pointer in the linked list
if next pointer and curr pointer is having same value then we increment the next pointer till they are unequal... | 1,788 | C++ | .cpp | 63 | 17.507937 | 134 | 0.441279 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,082 | longest_substring_without_repetition.cpp | OpenGenus_cosmos/code/online_challenges/src/leetcode/longest_substring_without_repetition/longest_substring_without_repetition.cpp | /*
*
* Problem: https://leetcode.com/problems/longest-substring-without-repeating-characters/
*
* Solution Description:
* "Sliding Window Approach"
*
* 1. We take two pointers i (left pointer) and j (right pointer).
* 2. We widen our window on the right side at each step (by incrementing j).
* 3. When... | 1,820 | C++ | .cpp | 53 | 29.886792 | 89 | 0.618966 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,083 | Sqrt(x).cpp | OpenGenus_cosmos/code/online_challenges/src/leetcode/Sqrt(x)/Sqrt(x).cpp | #include<bits/stdc++.h>
using namespace std;
// O(logn)
class Solution {
public:
int mySqrt(int x) {
double start=0,end=x;
for(int i=0;i<100;++i){
double mid = start + (end - start) / 2;
if(mid*mid<=x){
start = mid;
}else{
end = mid;
... | 445 | C++ | .cpp | 22 | 13.454545 | 50 | 0.463007 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,084 | minimum_number_of_days_to_make_m_bouquets.cpp | OpenGenus_cosmos/code/online_challenges/src/leetcode/minimum_number_of_days_to_make_m_bouquets/minimum_number_of_days_to_make_m_bouquets.cpp | #include<bits/stdc++.h>
using namespace std;
class Solution {
public:
int minDays(vector<int>& bloomDay, int m, int k) {
if(m > (int)bloomDay.size() / k){
return -1;
}
int start=1,end=*max_element(bloomDay.begin(), bloomDay.end()),res=-1;
while(start<=end){
... | 1,247 | C++ | .cpp | 46 | 16.847826 | 78 | 0.45508 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,085 | two_sum.cpp | OpenGenus_cosmos/code/online_challenges/src/leetcode/two_sum/two_sum.cpp | #include<bits/stdc++.h>
using namespace std;
//O(n^2)
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target){
vector<int>res;
for(int i=0;i<(int)nums.size();++i){
for(int j=i+1;j<(int)nums.size();++j){
if(nums[i]+nums[j]==target){
... | 695 | C++ | .cpp | 28 | 16.892857 | 54 | 0.484115 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | false | false | false | false | false | false |
10,086 | problem_023.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_023/problem_023.cpp | #include <bits/stdc++.h>
using namespace std;
int isAbundant(int x)
{
int sum = 0;
for(int i = 1; i * i <= x; i++)
{
if(x % i == 0)
{
if((x / i) == i)
{
sum += i;
}
else
{
sum += i + (x / i);
... | 1,080 | C++ | .cpp | 58 | 11 | 61 | 0.362475 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,087 | problem_011.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_011/problem_011.cpp | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n = 20;
int a[n][n];
// Passing the 20 * 20 array as input
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
cin >> a[i][j];
}
}
int dr[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dc[8] ... | 1,110 | C++ | .cpp | 45 | 13.2 | 69 | 0.268797 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,088 | problem_007.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_007/problem_007.cpp | #include <cmath>
#include <iostream>
#include <vector>
std::vector<long long int> primesUpto(size_t limit) // Function that implements the Sieve of Eratosthenes
{
std::vector<bool> primesBoolArray(limit, true);
std::vector<long long int> primesUptoLimit;
primesBoolArray[0] = primesBoolArray[1] = false;
... | 835 | C++ | .cpp | 23 | 31.130435 | 105 | 0.638614 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,089 | problem_006.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_006/problem_006.cpp | #include <iostream>
int main()
{
long long int sumOfSquares = 0LL;
long int squareOfSum = 0LL;
for (int n = 1; n <= 100; ++n)
{
sumOfSquares += (n * n);
squareOfSum += n;
}
squareOfSum *= squareOfSum;
std::cout << (squareOfSum - sumOfSquares) << "\n";
}
| 301 | C++ | .cpp | 13 | 18.538462 | 54 | 0.564912 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,090 | problem_102.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_102/problem_102.cpp | #include <cmath>
#include <iostream>
#include <fstream>
struct Coord
{
int x;
int y;
};
int doubleTriangleArea(Coord a, Coord b, Coord c) // Area doesn't actually need to be calculated either,
// just compared for equality
{
/*
* Coordinate area metho... | 1,659 | C++ | .cpp | 51 | 25.941176 | 116 | 0.573924 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,093 | problem_009.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_009/problem_009.cpp | #include <iostream>
int main()
{
for (int i = 1; i < 1000; ++i)
for (int j = 1; j < 1000; ++j)
{
for (int k = 1; k < 1000; ++k)
if (((i * i) + (j * j) == (k * k)) && ((i + j + k) == 1000))
{
std::cout << i * j * k << "\n";
... | 457 | C++ | .cpp | 16 | 19.25 | 76 | 0.368182 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
10,094 | problem_021.cpp | OpenGenus_cosmos/code/online_challenges/src/project_euler/problem_021/problem_021.cpp | #include <iostream>
int sumProperDivisors(int n)
{
int sum = 0;
for (int i = 1; i * i <= n; ++i)
if (n % i == 0)
{
sum += i;
if (n / i != i)
sum += n / i;
}
return sum - n;
}
bool isAmicableNumber(int n)
{
int m = sumProperDivisors(n);
... | 551 | C++ | .cpp | 27 | 14.814815 | 47 | 0.471154 | OpenGenus/cosmos | 13,556 | 3,669 | 2,596 | GPL-3.0 | 9/20/2024, 9:26:25 PM (Europe/Amsterdam) | false | false | true | false | false | true | false | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.