repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
choll/xtr
src/file_descriptor.cpp
// Copyright 2014, 2015, 2019, 2020 <NAME> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, p...
choll/xtr
include/xtr/formatters.hpp
<reponame>choll/xtr // Copyright 2021 <NAME> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge,...
choll/xtr
include/xtr/sink.hpp
<filename>include/xtr/sink.hpp // Copyright 2021 <NAME> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, mod...
choll/xtr
test/logger.cpp
<reponame>choll/xtr // Copyright 2020 <NAME> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge,...
choll/xtr
src/xtrctl.cpp
<gh_stars>1-10 // Copyright 2020 <NAME> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publ...
choll/xtr
include/xtr/detail/string_table.hpp
// Copyright 2020 <NAME> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute...
choll/xtr
include/xtr/log_macros.hpp
// Copyright 2019, 2020, 2021 <NAME> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish...
choll/xtr
test/throw.cpp
<gh_stars>1-10 // Copyright 2020 <NAME> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publ...
choll/xtr
test/command_client.hpp
<gh_stars>1-10 // Copyright 2021 <NAME> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publ...
choll/xtr
single_include/xtr/logger.hpp
<filename>single_include/xtr/logger.hpp /* MIT License Copyright (c) 2021 <NAME> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to us...
choll/xtr
include/xtr/detail/tsc.hpp
#ifndef XTR_DETAIL_TSC_HPP #define XTR_DETAIL_TSC_HPP #include "xtr/timespec.hpp" #include <cstdint> #include <ctime> #include <fmt/chrono.h> #include <fmt/format.h> namespace xtr::detail { struct tsc; std::uint64_t read_tsc_hz() noexcept; std::uint64_t estimate_tsc_hz() noexcept; inline std::uint...
choll/xtr
src/tsc.cpp
<reponame>choll/xtr<filename>src/tsc.cpp // Copyright 2020 <NAME> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use,...
choll/xtr
include/xtr/config.hpp
#ifndef XTR_CONFIG_HPP #define XTR_CONFIG_HPP /** * Sets the capacity (in bytes) of the queue that sinks use to send log data * to the background thread. Each sink will have an individual queue of this * size. Users are permitted to define this variable in order to set a custom * capacity. User provided capacities...
choll/xtr
include/xtr/detail/consumer.hpp
<reponame>choll/xtr // Copyright 2021 <NAME> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge,...
choll/xtr
src/command_path.cpp
// Copyright 2019, 2020, 2021 <NAME> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish...
choll/xtr
test/command_dispatcher.cpp
// Copyright 2021 <NAME> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute...
pduck27/CO2NanoDetector
src/main.cpp
// Code was mainly copied and overworked from other projects. // Thanks to: https://esp8266-server.de/CO2Ampel.html // and: https://xantorohara.github.io/led-matrix-editor #include <Arduino.h> #include <SoftwareSerial.h> #include <LedControl.h> // Led configuration #define MAX_DEVICES 1 #define CS_PIN 10 #define DIN...
cracked-machine/cpp_adg2188
tests/catch_main_app.cpp
#include <catch2/catch_all.hpp> #include <timer_manager.hpp> #include <adg2188.hpp> TEST_CASE("Test ADG2188", "[ADG2188]") { // Enable timer test fixture and start it in a new thread // TIM_TypeDef *timer = new TIM_TypeDef; // REQUIRE(stm32::TimerManager::initialise(timer)); // std::future<bool> tim_r...
cracked-machine/cpp_adg2188
src/adg2188.cpp
// MIT License // Copyright (c) 2022 <NAME> // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, p...
cracked-machine/cpp_adg2188
include/adg2188.hpp
<filename>include/adg2188.hpp // MIT License // Copyright (c) 2022 <NAME> // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // ...
SafeteeWoW/fuzz-zlib
deflate_uncompress_fuzzer.cc
// Author: SafeteeWow // Fuzzing test decompressing raw deflate format #include <stddef.h> #include <stdint.h> #include <string.h> #include <stdio.h> #define ZLIB_CONST 1 // To enable "const" keyword support in zlib. #include "zlib.h" static Bytef buffer[1024 * 1024] = { 0 }; // Entry point for LibFuzzer. extern ...
SafeteeWoW/fuzz-zlib
zlib_gzip_uncompress_fuzzer.cc
// Copyright 2015 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 <stddef.h> #include <stdint.h> #include <string.h> #include "zlib.h" static Bytef buffer[1024 * 1024] = { 0 }; // Entry point for LibFuzzer. e...
steventfan/CS100
Lab 8/visitor.cpp
#include "visitor.h" void PrintVisitor::rootNode() { return; } void PrintVisitor::sqrNode() { output.append("Squared "); } void PrintVisitor::multNode() { output.append("Multiply "); } void PrintVisitor::subNode() { output.append("Subtract "); } void PrintVisitor::addNode() { output.append("Add...
steventfan/CS100
Lab 5/testPrint.cpp
<gh_stars>0 #include <iostream> #include "component.h" #include "decorator.h" #include "container.h" #include "strategy.h" #include "BasePrint.h" #include "BaseFactory.h" #include <iostream> // class Test // { // public: // double number; // BaseFactory *pointer; // BasePrint *print; ...
steventfan/CS100
Lab 8/iterator.cpp
<gh_stars>0 #include "iterator.h" void OperatorIterator::first() { current_ptr = self_ptr->get_left(); } void OperatorIterator::next() { /*if(!is_done() && current_ptr == self_ptr->get_left() ) { current_ptr = self_ptr->get_right(); } else { current_ptr = NULL; }*/ if(current_ptr =...
steventfan/CS100
Lab 5/BaseFactory.cpp
<reponame>steventfan/CS100<gh_stars>0 #include "BaseFactory.h" BasePrint * DoubleFactory::generatePrint(double value) { return new DoublePrint(value); } BasePrint * HexFactory::generatePrint(double value) { return new HexPrint(value); } BasePrint * BinaryFactory::generatePrint(double value) { return new ...
steventfan/CS100
Lab 5/VectorContainer.cpp
#include "container.h" #include "strategy.h" /* Pure Virtual Functions */ // insert the top pointer of the tree into the container void VectorContainer::add_element(Base* element) { vectorContainer.push_back(element); } // iterate through the trees and output values void VectorContainer::print() { BasePrint *...
steventfan/CS100
Lab 3/test.cpp
#include <iostream> #include "component.h" #include "container.h" #include "strategy.h" // #include necessary classes using namespace std; int main() { Op* op7 = new Op(7); Op* op4 = new Op(4); Op* op3 = new Op(3); Op* op2 = new Op(2); Mult* A = new Mult(op7, op4); Add* B = new Add(op3, A); ...
steventfan/CS100
Lab 5/ListContainer.cpp
#include "container.h" #include "strategy.h" void ListContainer::add_element(Base* element) { listContainer.push_back(element); } // iterate through the trees and output value void ListContainer::print() { /*it = listContainer.begin(); while(it != listContainer.end() ) { std::cout << (*it)->ev...
steventfan/CS100
Lab 5/container.cpp
#include "container.h" void Container::set_sort_function(Sort* sort_function) { this->sort_function = sort_function; }
steventfan/CS100
Lab 4/test.cpp
<filename>Lab 4/test.cpp #include <iostream> #include "component.h" #include "decorator.h" #include "container.h" #include "strategy.h" // #include necessary classes using namespace std; int main() { Op* op7 = new Op(7.1); Op* op4 = new Op(4.2); //Op* op4 = new Op(-1000.2); Op* op3 = new Op(3.3); ...
steventfan/CS100
Lab 5/BasePrint.cpp
#include "BasePrint.h" void DoublePrint::print() { std::cout << value; } void HexPrint::print() { //std::cout << std::hexfloat; std::cout << value; } void BinaryPrint::print() { std::bitset<16> number(value); std::cout << number; }
r10o/boost-python_example
hello.cpp
<filename>hello.cpp #include <boost/python.hpp> char const* greet() { return "Hello, world!"; } BOOST_PYTHON_MODULE(hello) { boost::python::def("greet", greet); }
TheRedRover/brainfuck
brainfuck/bfmachine.cpp
<gh_stars>0 #include "bfmachine.hpp" #include <stack> #include <utility> void cmd::set_next(cmd *nxt) { _next = nxt; } cmd *cmd::get_next() { return _next; } int cmd::execute(int cell_value) { return 0; } command_types cmd::get_cmd_type() { return c; } cmd::~cmd() { } cmd *cmd::get_clear_next() { ...
TheRedRover/brainfuck
test/test.cpp
#include "../brainfuck/bfmachine.hpp" #include <cassert> #include <fstream> #include <iostream> // std::cout #include <sstream> #include <string> // std::string std::string get_cout_string(bfmachine &c) { std::stringstream buffer; std::streambuf *prevcoutbuf = std::cout.rdbuf(buffer.rdbuf()); c.run(); ...
TheRedRover/brainfuck
brainfuck/bfmachine.hpp
<gh_stars>0 #ifndef BF_MACHINE_BFMACHINE_HPP #define BF_MACHINE_BFMACHINE_HPP #include <iostream> #include <memory> #include <vector> enum commands { MINUS = '-', PLUS = '+', RIGHT = '>', LEFT = '<', POINT = '.', COMA = ',', RIGHT_BRACKET = ']', LEFT_BRACKET = '[' }; enum command_types...
TheRedRover/brainfuck
brainfuck/bfmake.cpp
<filename>brainfuck/bfmake.cpp #include "bfmachine.hpp" #include <fstream> int main(int argc, char *argv[]) { try { bfmachine c; switch (argc) { case 2: { c.init(argv[1]); c.run(); break; } case 3: { if (std::string...
trehanarsh/Codechef-Solutions
CHEFDETE.cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; unordered_set<int> st; for (int i = 0; i < n; ++i) { int tmp; cin>>tmp; st.insert(tmp); } if (n==1) { printf("0\n"); return 0; } for (int i = 1; i <= n; ++i) { if (st.find(i)==st.end()) { printf("...
trehanarsh/Codechef-Solutions
BROKPHON.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n; cin>>n; int a[n]; for (int i = 0; i < n; ++i) { cin>>a[i]; } int ans=0; for (int i = 1; i < n - 1 ; ++i) { if ((a[i]!=a[i-1]) || (a[i] != a[i+1])) { ans++; } } i...
trehanarsh/Codechef-Solutions
AMR15A.cpp
<reponame>trehanarsh/Codechef-Solutions #include <bits/stdc++.h> using namespace std; #define ll long long int main() { int n,even=0,odd=0; cin>>n; int a[n]; for (int i = 0; i < n; ++i) { cin>>a[i]; } for (int i = 0; i < n; ++i) { if (a[i]%2==0) { even++; } else odd++; } ...
trehanarsh/Codechef-Solutions
COOK82A.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { std::map<string, int> mp; for (int i = 0; i < 4; ++i) { string s; cin>>s; int score; cin>>score; mp[s] = score; } if ((mp["Malaga"]>mp["RealMadrid"]) && (mp["Eibar"] < mp["Barcelona"])) ...
trehanarsh/Codechef-Solutions
BINTREE.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int x,y; cin>>x>>y; int xx=x; int yy=y; std::vector<int> a,b; while(x>=1) { a.push_back(x); x/=2; } while(y>=1) { b.push_back(y); y/=2; } int target; for (int i = 0...
trehanarsh/Codechef-Solutions
CHEFSUBA.cpp
#include <bits/stdc++.h> using namespace std; int maxVal(int x, int y) { return (x > y)? x: y; } int getMid(int s, int e) { return s + (e -s)/2; } int RMQUtil(int *st, int ss, int se, int qs, int qe, int index) { if (qs <= ss && qe >= se) return st[index]; if (se < qs || ss > qe) ...
trehanarsh/Codechef-Solutions
MATCHIT.cpp
<reponame>trehanarsh/Codechef-Solutions #include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 #define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl; #define take(A,n) for(ll i=0;i<n;++i)cin>>A[i]; // for(auto& it : m) void fastio(){ios_base::sync_with_stdio(false);cin.t...
trehanarsh/Codechef-Solutions
RIGHTRI.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; int count=0; while(t--) { int x1,y1,x2,y2,x3,y3; cin>>x1>>y1>>x2>>y2>>x3>>y3; int dist1=abs(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))); int dist2=abs(((x3-x2)*(x3-x2))+((y3-y2)*(y3-y2))); int dist3=abs(((x1-x3)*(x1-x3))+((y1...
trehanarsh/Codechef-Solutions
ALEXNUMB.cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int t; cin>>t; while(t--) { int n; cin>>n; unordered_set<ll> st; for (int i = 0; i < n; ++i) { ll tmp; cin>>tmp; st.insert(tmp); } printf("%lld\n",(ll)st.size()*(ll)(st.size()-1)/(ll)2 ); } ...
trehanarsh/Codechef-Solutions
PLAYFIT.cpp
<gh_stars>0 #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n; cin>>n; int a[n]; for (int i = 0; i < n; ++i) { cin>>a[i]; } int ans=0, curr_min=a[0]; for (int i = 0; i < n; ++i) { curr_min=min(curr_min, a[i]); ans=max(a[i]-curr...
trehanarsh/Codechef-Solutions
GERMANDE.cpp
#include <bits/stdc++.h> using namespace std; #define ll long long int getMid(int s, int e) { return s + (e -s)/2; } int getSumUtil(int *st, int ss, int se, int qs, int qe, int si) { if (qs <= ss && qe >= se) return st[si]; if (se < qs || ss > qe) return 0; int mid = get...
trehanarsh/Codechef-Solutions
THESAV.cpp
<filename>THESAV.cpp #include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t; cin>>t; while(t--) { string s; cin>>s; bool able=true; int count=0; for (int i = 0; i < s.length(); ++i) { if (s[i]=='*') { count=2; } if (s[i]=='0') { ...
trehanarsh/Codechef-Solutions
LAPIN.cpp
<gh_stars>0 #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { string s; cin>>s; int a[26],b[26]; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for (int i = 0; i < s.length()/2; ++i) { a[s[i]-'a']++; } int x; if (s.length()%2) { x=1...
trehanarsh/Codechef-Solutions
TACHSTCK.cpp
#include <bits/stdc++.h> using namespace std; int main() { int n,d; cin>>n>>d; int a[n]; for (int i = 0; i < n; ++i) { cin>>a[i]; } sort(a,a+n); int ans=0; for (int i = 0; i < n; i+=2) { if (abs((a[i]-a[i+1]))<=d) { ans++; } else { i--; } } printf("%d\n",ans ); ...
trehanarsh/Codechef-Solutions
ERROR.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { string s; cin>>s; if ((s.find("010")!=string::npos)||((s.find("101")!=string::npos))) { printf("Good\n"); } else printf("Bad\n"); } return 0; }
trehanarsh/Codechef-Solutions
CHEFZOT.cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int ans=0,count=0; for (int i = 0; i < n; ++i) { int tmp; cin>>tmp; if (tmp==0) { count=0; } else count++; ans=max(ans,count); } printf("%d\n",ans ); return 0; }
trehanarsh/Codechef-Solutions
ANUARM.cpp
<filename>ANUARM.cpp #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,m; cin>>n>>m; int orderes[m]; for (int i = 0; i < m; ++i) { cin>>orderes[i]; } int small=*min_element(orderes,orderes+m); int big=*max_element(orderes,orderes+m); f...
trehanarsh/Codechef-Solutions
HELPLIRA.cpp
<reponame>trehanarsh/Codechef-Solutions #include <bits/stdc++.h> using namespace std; int area(int *x,int * y) { double ans = abs( ( (x[1] - x[0]) * (y[2] - y[0]) ) - ( (x[2] - x[0])* (y[1] - y[0]) ) ); return ans/2; } int main() { int n; cin>>n; double minival = INT_MAX, maxival = INT_MIN; i...
trehanarsh/Codechef-Solutions
RAINBOW.cpp
<reponame>trehanarsh/Codechef-Solutions #include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t; cin>>t; while(t--) { int n; cin>>n; int a[n][n]; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin>>a[i][j]; } } unordered_set...
trehanarsh/Codechef-Solutions
ADACRA.cpp
<filename>ADACRA.cpp #include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t; cin>>t; while(t--) { string s; cin>>s; int seg = 0; int prev = s[0]; int i; for (i = 1; i < s.length(); ++i) { if (prev != s[i]) { if (prev == 'D') { se...
trehanarsh/Codechef-Solutions
LUCKY5.cpp
<reponame>trehanarsh/Codechef-Solutions #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { string s; cin>>s; int ans=0; for (int i = 0; i < s.length(); ++i) { if (s[i]!='4'&&s[i]!='7') { ans++; } } printf("%d\n",ans ); } return 0; ...
trehanarsh/Codechef-Solutions
HELLO.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { double d,u; int n; cin>>d>>u>>n; double val = 123465678; int ansidx = -1; for (int i = 0; i < n; ++i) { double m,r,c; cin>>m>>r>>c; double curr_val = r*u + c/m; if (curr_val < val) ...
trehanarsh/Codechef-Solutions
ANKTRAIN.cpp
<reponame>trehanarsh/Codechef-Solutions<gh_stars>0 #include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d",&t); while(t--) { int n; cin>>n; if (n%8==1) { printf("%dLB\n",n+3 ); } if (n%8==2) { printf("%dMB\n",n+3 ); } if (n%8==3) { printf("%dUB\n...
trehanarsh/Codechef-Solutions
SUPVIL.cpp
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t; cin>>t; while(t--) { int n; cin>>n; int hreo=0; int vill=0; int i; bool done=false; int finalans=0; for (i = 0; i < n; ++i) { string s; cin>>s; if (s.length()>=3) { if ((...
trehanarsh/Codechef-Solutions
CSUB.cpp
<gh_stars>0 #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int t; cin>>t; while(t--) { ll n; cin>>n; string s; cin>>s; ll oc=0; for (int i = 0; i < n; ++i) { if (s[i]=='1') { oc++; } } ll ans=(oc*(oc-(ll)1)/(ll)2)+oc; printf("%...
trehanarsh/Codechef-Solutions
PUPPYGM.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int a,b; cin>>a>>b; if ((a%2)==0||(b%2)==0) { printf("Tuzik\n"); } else printf("Vanka\n"); } return 0; }
trehanarsh/Codechef-Solutions
PREFINVS.cpp
<reponame>trehanarsh/Codechef-Solutions #include <bits/stdc++.h> using namespace std; #define ll long long int main() { string s; cin>>s; int n= s.length(); reverse(s.begin(),s.end()); bool found = false; int count = 0; char old = '0'; for (int i = 0; i < s.length(); ++i) { if (s[i]=='1') {...
trehanarsh/Codechef-Solutions
XENRANK.cpp
<filename>XENRANK.cpp #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int t; cin>>t; while(t--) { ll x,y; cin>>x>>y; ll n=x+y; ll ans = (1+n)*(n)/2; ans +=x+1; printf("%lld\n", ans); } return 0; }
trehanarsh/Codechef-Solutions
ROBOTG.cpp
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t; cin>>t; while(t--) { int n,m; cin>>n>>m; string s; cin>>s; int ps=0; int ud=0; bool safe=true; int hps=0,lps=0; for (int i = 0; i < s.length(); ++i) { if (s[i]=='L') { ps--; ...
trehanarsh/Codechef-Solutions
CATSDOGS.cpp
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t; cin>>t; while(t--) { ll c,d,l; cin>>c>>d>>l; if ((l%4==0)&&(l<=(c+d)*4)&&(l>=((c>2*d)?(4*(c-d)):(d*4)))) { printf("yes\n"); } else { printf("no\n"); } } return 0; }
trehanarsh/Codechef-Solutions
SUMQ.cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define MOD 1000000007 int main() { int t; cin>>t; while(t--) { int p,q,r; scanf("%d %d %d",&p,&q,&r); ll a[p],b[q],c[r]; for (int i = 0; i < p; ++i) scanf("%lld",a+i); for (int i = 0; i < q; ++i) scanf("%lld",b+i); ...
trehanarsh/Codechef-Solutions
COMPILER.cpp
<filename>COMPILER.cpp #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { string s; cin>>s; int len=0; int opened = 0; for (int i = 0; i < s.length(); ++i) { if (s[i] == '<') { opened++; } else opened--; if (opened == 0) ...
trehanarsh/Codechef-Solutions
WSITES01.cpp
#include <bits/stdc++.h> using namespace std; typedef struct trieNode { struct trieNode* children[26]; bool isLeaf; }trieNode; trieNode *getNode() { trieNode* pNode = NULL; pNode = (trieNode*)malloc(sizeof(trieNode)); pNode->isLeaf = false; for (int i = 0; i < 26; ++i) { pNode->children[i] ...
trehanarsh/Codechef-Solutions
DECSTR.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n; cin>>n; int a=n%25; if (a!=0) { for (char i = a+'a'; i >='a' ; --i) { printf("%c",i ); } } int b=n/25; while(b--) { for (char i = 'z'; i >='a' ; --i) { printf...
trehanarsh/Codechef-Solutions
NAME1.cpp
<filename>NAME1.cpp<gh_stars>0 #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { string s1,s2; cin>>s1>>s2; int n; cin>>n; int parent[26]; memset(parent, 0, sizeof(parent)); string name[n]; for (int i = 0; i < s1.length(); ++i) { parent[s...
trehanarsh/Codechef-Solutions
POTATOES.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; bool a[10000]; memset(a,false,sizeof(a)); for (int i = 2; i < 10000; ++i) { if (a[i]==false) { for (int j = i+i; j < 10000; j+=(i)) { a[j]=true; } } } while(t--) { int x,y; cin>>x>>y; for (i...
trehanarsh/Codechef-Solutions
DAILY.cpp
#include <bits/stdc++.h> using namespace std; long long ncr(long long n,long long r) { if (r>n) { return 0; } if(r > n / 2) r = n - r; long long ans = 1; int i; for(i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } int main() { long long x,n; cin>>x>>n...
trehanarsh/Codechef-Solutions
CHEFAPAR.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n; cin>>n; bool finecount=false; int ans=0; for(int i=0;i<n;i++) { int curr; cin>>curr; if (curr==0) { finecount=true; } if (finecount&&(curr==0)) { ans+=(1100); ...
trehanarsh/Codechef-Solutions
KOL16B.cpp
<filename>KOL16B.cpp #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; int tc=1; while(t--) { int n; cin>>n; std::vector<int> a,b; for (int i = 0; i < n; ++i) { int k; cin>>k; int x=(k%(1<<16)); int y=(k/(1<<16)); a.push_back(x); b.push_back(y)...
trehanarsh/Codechef-Solutions
SEGM01.cpp
<reponame>trehanarsh/Codechef-Solutions #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { string s; cin>>s; int possible = true; bool one = false; int flag = 0; for (int i = 0; i < s.length(); ++i) { if (flag ==0) { if (s[i]=='1') { ...
trehanarsh/Codechef-Solutions
SPOON.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,c; cin>>n>>c; string a[n]; string b[c]; for (int i = 0; i < n; ++i) { cin>>a[i]; } for (int i = 0; i < n; ++i) { for (int j = 0; j < c; ++j) { if ((a[i][j]>='A')&&(a[i][j]<...
trehanarsh/Codechef-Solutions
CHEFSETC.cpp
<filename>CHEFSETC.cpp #include <bits/stdc++.h> using namespace std; #define ll long long vector< vector<int> > getAllSubsets(vector<int> set) { vector< vector<int> > subset; vector<int> empty; subset.push_back( empty ); for (int i = 0; i < set.size(); i++) { vector< vector<int>...
trehanarsh/Codechef-Solutions
LEPERMUT.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n; cin>>n; int a[n]; for (int i = 0; i < n; ++i) { cin>>a[i]; } bool good=true; for (int i = 0; i < n; ++i) { for (int j = i+2; j < n; ++j) { if (a[i]>a[j]) { good...
trehanarsh/Codechef-Solutions
AMMEAT.cpp
#include <bits/stdc++.h> using namespace std; #define ll unsigned long long int main() { int t; cin>>t; while(t--) { int n; ll m; cin>>n>>m; ll a[n]; for (int i = 0; i < n; ++i) { cin>>a[i]; } sort(a,a+n,greater<ll>()); ll sum=0; bool done=false; for (int i = 0; i < n; +...
trehanarsh/Codechef-Solutions
ARRANGE.cpp
#include <bits/stdc++.h> using namespace std; int reverse(int n,int k) { std::vector<int> v; while(n>0) { v.push_back(n%2); n/=2; k--; } while(k--) { v.push_back(0); } int ans=0; for (int i = 0; i < v.size(); ++i) { ans = (ans*2)+v[i]; } return ans; } int main() { int t; ...
trehanarsh/Codechef-Solutions
MAKETRI.cpp
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { std::map<ll, ll> stmap; unordered_set<ll> memo; ll n,l,r; cin>>n>>l>>r; ll a[n]; for (ll i = 0; i < n; ++i) { cin>>a[i]; } sort(a,a+n); for (ll i = 0; i < n-1; ++i) { ll j=i+1; ll lb=max(l,(1+a[j]...
trehanarsh/Codechef-Solutions
POINTS.cpp
<filename>POINTS.cpp<gh_stars>0 #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n; cin>>n; std::vector<pair<int,int> > v; std::vector<pair<int,int> > all; for (int i = 0; i < n; ++i) { int x,y; cin>>x>>y; v.push_back(make_pair(x,y)); ...
trehanarsh/Codechef-Solutions
APPROX.cpp
#include <bits/stdc++.h> using namespace std; int main() { int a = 46870; int b = 33102; int limit = 1000004; string s = ""; while(limit--) { if (a/b == 0) { s+='0'; } else { char c = ((a/b) + '0'); a%=b; s+=c; } a*=10; } int t; cin>>t; while(t--) { in...
trehanarsh/Codechef-Solutions
PCYCLE.cpp
<reponame>trehanarsh/Codechef-Solutions<filename>PCYCLE.cpp #include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int a[n]; unordered_set<int> visited; for (int i = 0; i < n; ++i) { cin>>a[i]; a[i]--; } int count=0; std::vector<std::vector<int> > ans; while(count<n) { ...
trehanarsh/Codechef-Solutions
AMSGAME1.cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int t; cin>>t; while(t--) { int n; cin>>n; ll a[n]; for (int i = 0; i < n; ++i) { cin>>a[i]; } ll ans=a[0]; for (int i = 1; i < n; ++i) { ans=__gcd(a[i],ans); } printf("%lld\n",ans );...
trehanarsh/Codechef-Solutions
ENTEXAM.cpp
<reponame>trehanarsh/Codechef-Solutions<filename>ENTEXAM.cpp #include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t; cin>>t; while(t--) { ll n,k,e,m; cin>>n>>k>>e>>m; ll stdsum[n]; memset(stdsum,0,sizeof(stdsum)); for (ll i = 0; i < n-1; ++i) { for (ll ...
trehanarsh/Codechef-Solutions
BOOKCHEF.cpp
<gh_stars>0 #include <bits/stdc++.h> using namespace std; #define ll long long int main() { int n,m; cin>>n>>m; int splf[n]; for (int i = 0; i < n; ++i) { cin>>splf[i]; } int f1[m],p1[m]; int f2[m],p2[m]; string s1[m]; string s2[m]; int it1=0; int it2=0; for (int i = 0; i < m; ++i) ...
trehanarsh/Codechef-Solutions
UNIONSET.cpp
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int t; scanf("%d",&t); while(t--) { int n,k; scanf("%d %d",&n,&k); vector<int> a[n]; std::vector<int> sum(n); for (int i = 0; i < n; ++i) { int len; scanf("%d",&len); while(len--...
trehanarsh/Codechef-Solutions
KOL16J.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; int tc=1; while(t--) { int n; cin>>n; int a[n],c[501]; memset(c,0,sizeof(c)); int maxi=INT_MIN; for (int i = 0; i < n; ++i) { cin>>a[i]; if (a[i]>maxi) { maxi=a[i]; } c[a[i]]++; } b...
trehanarsh/Codechef-Solutions
BRLADDER.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int a,b; cin>>a>>b; if (abs(b-a)==1) { if (min(a,b)%2) { printf("YES\n"); } else printf("NO\n"); } else if (abs(b-a)==2) { printf("YES\n"); } else printf(...
trehanarsh/Codechef-Solutions
RESQ.cpp
#include <stdio.h> #include <math.h> int abs(int n) { return n>0?n:(-1)*n; } int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int kk=sqrt(n); int i; for (i = kk; i >= 1; --i) { if (n%i==0) { printf("%d\n",abs(i-(n/i)) ); break; } }...
trehanarsh/Codechef-Solutions
CHEFSTON.cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int t; cin>>t; while(t--) { ll n,k; cin>>n>>k; ll a[n],b[n]; for (int i = 0; i < n; ++i) { cin>>a[i]; } for (int i = 0; i < n; ++i) { cin>>b[i]; } ll ans=LONG_MIN; for (int i = 0; i <...
trehanarsh/Codechef-Solutions
RRSUM.cpp
#include <bits/stdc++.h> using namespace std; int main() { long long n,m; cin>>n>>m; while(m--) { long long num; cin>>num; if (num<=n+1||num>3*n) { printf("0\n"); } else { num-=n; if (num<=n) { printf("%lld\n", num-1); } else { num=2*n-num; prin...
trehanarsh/Codechef-Solutions
TAVISUAL.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,c,q; cin>>n>>c>>q; while(q--) { int l,r; cin>>l>>r; if (c>=l&&c<=r) { c=r-(c-l); } } printf("%d\n",c ); } return 0; }
trehanarsh/Codechef-Solutions
TOTR.cpp
<filename>TOTR.cpp #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; string s; cin>>s; while(t--) { string msg; cin>>msg; for (int i = 0; i < msg.length(); ++i) { if (msg[i]>='a'&&msg[i]<='z') { printf("%c", s[msg[i]-'a']); } else if (msg[i]>='A'&&...
trehanarsh/Codechef-Solutions
MAXDIFF.cpp
<reponame>trehanarsh/Codechef-Solutions<gh_stars>0 #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,k; cin>>n>>k; int a[n]; k=min(k,n-k); int sum=0; for (int i = 0; i < n; ++i) { cin>>a[i]; sum+=a[i]; } sort(a,a+n); int sum2=0;...
trehanarsh/Codechef-Solutions
BUYING2.cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,x; cin>>n>>x; int mini=INT_MAX; int sum=0; for (int i = 0; i < n; ++i) { int tmp; cin>>tmp; mini=min(tmp,mini); sum+=tmp; } if ((sum/x)==((sum-mini)/x)) { printf("-1\n")...
trehanarsh/Codechef-Solutions
NOTINCOM.cpp
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t; cin>>t; while(t--) { int n,m; cin>>n>>m; std::vector<int> v; unordered_set<int> b; for (int i = 0; i < n; ++i) { int tmp; cin>>tmp; v.push_back(tmp); } for (int i = 0; i < m; ++i) ...