From 3b975a913636c6e54e2e2c0376461b0f0db14eec Mon Sep 17 00:00:00 2001 From: Kenzo1212 Date: Fri, 21 Oct 2022 19:13:54 +0530 Subject: [PATCH 1/2] create equalizing problem --- .vscode/settings.json | 3 - ALTSUFF.cpp | 118 --- Add Equal Difference Problem Code .cpp | 32 - Add XOR-PAL code.cpp/Hacktoberfest-2022 | 25 - Basic pattern java | 184 ---- C++.md | 608 ------------ C++/#include 0 bytes C++/ashish_gup.cpp | 69 -- C++/bear_ladder.cpp | 64 -- C++/bin_mex.cpp | 43 - C++/binary.cpp | 21 - C++/bubbleshort.cpp | 29 - C++/buying_new_tables.cpp | 40 - C++/chef_and_bulb_invention.cpp | 31 - C++/chef_and_masks.cpp | 33 - C++/chef_and_round_run.cpp | 88 -- C++/chef_and_trump_cards.cpp | 98 -- C++/chef_and_wedding arrangements.cpp | 47 - C++/chef_gp.cpp | 57 -- C++/chef_rotine.cpp | 41 - C++/coder_life.cpp | 41 - C++/countwords.cpp | 14 - C++/cyclic_sort | 43 - C++/digitalclock.cpp | 53 - C++/div.cpp | 39 - C++/divisor.cpp | 18 - C++/eqdiffer.cpp | 38 - C++/even_diff.cpp | 26 - C++/evenorodd.cpp | 35 - C++/find_LCA_binary_tree.cpp | 19 - C++/find_diameter_binary_trees.cpp | 57 -- C++/football.cpp | 34 - C++/gany_house.cpp | 37 - C++/gcpd.cpp | 57 -- C++/gift.cpp | 51 - C++/greaterAverage.cpp | 26 - C++/inter_xor.cpp | 95 -- C++/intersection-of-two-linked-lists.cpp | 26 - C++/matrix.cpp | 51 - C++/maxima.cpp | 43 - C++/maximise_islands.cpp | 131 --- C++/mutated-minions.cpp | 51 - C++/ors_of_ands.cpp | 63 -- C++/painter_partition_dp.cpp | 49 - C++/palindrome_linked_list.cpp | 57 -- C++/pathetic_sums.cpp | 38 - C++/recipe.cpp | 22 - C++/reverseLinkedList.cpp | 41 - C++/sieve_of_eratosthenes.cpp | 27 - C++/slowSolution.cpp | 32 - C++/solider and bananas.cpp | 22 - C++/sumofarray.cpp | 45 - C++/that-is-my-score.cpp | 84 -- C++/theblockgame.cpp | 28 - C++/this_score.cpp | 40 - C++/tictac.cpp | 137 --- C++/totalPrizeMoney.cpp | 14 - C++/whats_name.cpp | 57 -- CNTRIBUTING.MD | 43 - CODE_OF_CONDUCT.md | 127 --- CONTRIBUTING.MD | 10 - Chef_And_His_Characters.java | 21 - Closest_vowel.cpp | 42 - CountSort.java | 52 - Equal Difference Problem Code .cpp | 32 - EqualCoins.cpp | 44 - Equalize_ab | 27 - Heart_Pattern_Printer.cpp | 39 - Java/Arrays java | 182 ---- Java/Chef and Socks- CodeChef.java | 0 Java/Home_For_Chef.java | 902 ------------------ Java/Stack concept java | 140 --- Java/demo.java | 1 - Java/java sorting Algorithm | 158 --- Java/max_min_dif.c | 31 - LICENSE | 21 - Make A and B equal .cpp | 38 - Python/AI Analysing Code.py | 6 - Python/ANSLEAK.py | 17 - Python/ATM.py | 6 - Python/Avoid Fix Point.py | 9 - Python/Biryani.py | 4 - Python/COMPRESSVD.py | 31 - Python/Car or Bus.py | 8 - Python/Careless Chef.py | 8 - Python/Cats and a Mouse.py | 37 - Python/Chef and NextGen.py | 6 - Python/Ciel and A-B Problem.py | 21 - Python/Compare the Triplets.py | 56 -- Python/Count The Notebook.py | 6 - Python/Daanish and Problems.py | 8 - Python/Day of the Programmer.py | 34 - Python/Diagonal Difference.py | 42 - Python/Enormous Input Test.py | 6 - Python/GCD and LCM.py | 6 - Python/Gross Salary.py | 6 - Python/Hostel Room.py | 8 - Python/How Many Digits.py | 5 - Python/Left Rotation.py | 35 - Python/Length of Last Word | 7 - Python/List Comprehensions.py | 12 - Python/Longest AND Subarray.py | 15 - Python/Mahasena.py | 12 - Python/Maximise the Subsequence Sum.py | 14 - Python/Maximum Weight Difference.py | 8 - Python/Migratory Birds.py | 37 - Python/Most Frequency.py | 15 - Python/Penalty Shootout 2.py | 35 - Python/Possible Victory.py | 8 - Python/Racing Horses.py | 10 - Python/Reverse The Number.py | 5 - Python/Runner-Up Score.py | 4 - Python/Smallest Numbers of Notes.py | 8 - Python/Suspense-String.py | 20 - Python/Total Expenses.py | 10 - Python/Turbo Sort.py | 5 - Python/World Chess Championsh.py | 14 - Python/XOR Palindrome.py | 18 - Python/Yet Another Palindrome Problem.py | 24 - Python/weight balance.py | 12 - README.md | 88 -- TrappingWater.cpp | 35 - Yet Another Palindrome Problem Code.cpp | 41 - chef_sugarcane.cpp | 18 - circular_track.cpp | 30 - codechef.c++ | 46 - enormous_input.c | 13 - equalizing.py | 3 + java.md | 456 --------- laptop_recommendations.cpp | 33 - simple-compound-interest.java | 19 - solidity.md | 600 ------------ 201 files changed, 3 insertions(+), 10567 deletions(-) delete mode 100644 .vscode/settings.json delete mode 100644 ALTSUFF.cpp delete mode 100644 Add Equal Difference Problem Code .cpp delete mode 100644 Add XOR-PAL code.cpp/Hacktoberfest-2022 delete mode 100644 Basic pattern java delete mode 100644 C++.md delete mode 100644 C++/#include -using namespace std; -#define ll long long -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - - ll t, n, k, i, j; - string a; - cin>>t; - - for(;t--;) - { - cin>>n>>k; - ll op[n], left[n], right[n]; - - cin>>a; - - for(i=0; i=0; i--) - { - if(a[i]=='1'){ - j=i; - }else{ - if(j!=-1){ - right[i]=j-i; - } - } - } - - - - - j=-1; - - for(i=0; i=0; i--) - { - if(a[i]=='0'){ - j=i; - }else{ - if(j!=-1){ - right[i]=j-i; - } - } - } - - - for(i=0; i -#define ll long long int -#include -using namespace std; - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int test; - cin>>test; - while(test--){ - ll n; - cin>>n; - ll temp; - map mp; - for(ll i=0;i>temp; - mp[temp]++; - } - if(n<=2) cout<<0< -using namespace std; - -int main() { - ios_base::sync_with_stdio(false); //just increasing the speed - cin.tie(0); - cout.tie(0); - int test; - cin>>test; - while(test--){ - int n; - cin>>n; - string s; - cin>>s; - int ct=0; //stores the count - for(int i=0;i=1;r--){ - System.out.print(" *"); - } - - System.out.println(); - } - } - - public static void inverted_halfPyyramid_with_number(int n){ - for(int i=1;i<=n;i++){ - for(int j=1;j<=n-i+1;j++){ - System.out.print(j+" "); - } - System.out.println(); - } - } - - public static void floyd_triangle(int n){ - int temp=1; - for(int i=1;i<=n;i++){ - for(int j=1;j<=i;j++){ - System.out.print(temp+" "); - temp++; - } - System.out.println(); - } - } - - public static void triangle_0_1(int n){ - for(int i=0;i=i;j--){ - System.out.print(j); - } - for(int j=2;j<=i;j++){ - System.out.print(j); - } - - System.out.println(); - } - } - - public static void butterfly(int n){ - - for(int i=1;i<=n;i++){ - for(int j=1;j<=i;j++){ - System.out.print(" *"); - } - for(int j=1;j<=2*(n-i);j++){ - System.out.print(" "); - } - for( int j=1;j<=i;j++){ - System.out.print(" *"); - } - System.out.println(); - } - - for(int i=n;i>=1;i--){ - for(int j=1;j<=i;j++){ - System.out.print(" *"); - } - for(int j=1;j<=2*(n-i);j++){ - System.out.print(" "); - } - for( int j=1;j<=i;j++){ - System.out.print(" *"); - } - System.out.println(); - } - } - - public static void solid_rhombus(int n){ - for(int i=1;i<=n;i++){ - for(int j=1;j<=n-i;j++){ - System.out.print(" "); - } - for(int j=1;j<=n;j++){ - System.out.print(" *"); - } - System.out.println(); - } - } - public static void hollow_rhombus( int n){ - for(int i=1;i<=n;i++){ - for(int j=1;j<=n-i;j++){ - System.out.print(" "); - } - for(int j=1;j<=n;j++){ - if(j==1 || j==n || i==1 ||i==n ){ - System.out.print("*"); - }else{ - System.out.print(" "); - } - - } - System.out.println(); - } - - } - - public static void diamond(int n){ - for(int i=1;i<=n;i++){ - for(int j=1;j<=n-i;j++){ - System.out.print(" "); - } - for(int j=1;j<=(2*i)-1;j++){ - System.out.print("*"); - } - System.out.println(); - } - - for(int i=n;i>=1;i--){ - for(int j=1;j<=n-i;j++){ - System.out.print(" "); - } - for(int j=1;j<=(2*i)-1;j++){ - System.out.print("*"); - } - System.out.println(); - } - } diff --git a/C++.md b/C++.md deleted file mode 100644 index 5966928..0000000 --- a/C++.md +++ /dev/null @@ -1,608 +0,0 @@ -# C++ QUICK REFERENCE / C++ CHEATSHEET - -The goal is to give a concise overview of basic, modern C++ (C++14). - - - -## Header Files - -```cpp - - #include: //It is used to perform input and output operations using functions scanf() and printf(). - #include: //It is used as a stream of Input and Output using cin and cout. - #include: //It is used to perform various string functionalities. - #include: //It is used to perform mathematical operations. - #include: //It is used to access set() and setprecision(). - #include: //It is used to perform signal handling functions like signal(). - #include: //It is used to perform standard argument functions like va_start(). - #include: //It is used to perform error handling operations like errno(). - #include: //It is used to control the data to read from a file. - #include: //It is used to perform functions related to date() and time() -``` - -## Preprocessor - -```cpp - // Comment to end of line - /* Multi-line comment */ -#include // Insert standard header file -#include //standard header for C++ -#pragma GCC optimize("Ofast") // for fast compilation -#pragma GCC optimize ("O3") -#pragma GCC target ("avx") -#include "myfile.h" // Insert file in current directory -#define X some text // Replace X with some text -#define F(a,b) a+b // Replace F(1,2) with 1+2 -#define X \ - some text // Multiline definition -#undef X // Remove definition -#if defined(X) // Conditional compilation (#ifdef X) -#else // Optional (#ifndef X or #if !defined(X)) -#endif // Required after #if, #ifdef -``` - -## Literals -### Integer Literal Constants -```cpp - 12; //An Integer(16 bits) - 12U; //An Unsigned Integer(16 bits) - 12L; //A Long Integer(32 bits) - 12LL; //A Long Long Integer(64 bits) -``` -### Floating Point Literal Constants -```cpp - 12.1; //A Double - 12.1F; //A Float - 12.1L; //A Long Double -``` - -### Character Literal Constants -```cpp -255, 0377, 0xff // Integers (decimal, octal, hex) -2147483647L, 0x7fffffffl // Long (32-bit) integers -123.0, 1.23e2 // double (real) numbers -'a', '\141', '\x61' // Character (literal, octal, hex) -'\n','\t','\b', '\\', '\'', '\"' // Newline,Tab,Backspace Backslash, Single quote, Double quote -"string\n" // Array of characters ending with newline and \0 -"hello" "world" // Concatenated strings -true, false // bool constants 1 and 0 -nullptr // Pointer type with the address of 0 -``` - -## Declarations - -```cpp -int x; // Declare x to be an integer (value undefined) -int x=255; // Declare and initialize x to 255 -short s; long l; // Usually 16 or 32 bit integer (int may be either) -char c='a'; // Usually 8 bit character -unsigned char u=255; -signed char s=-1; // char might be either -unsigned long x = - 0xffffffffL; // short, int, long are signed -float f; double d; // Single or double precision real (never unsigned) -bool b=true; // true or false, may also use int (1 or 0) -int a, b, c; // Multiple declarations -int a[10]; // Array of 10 ints (a[0] through a[9]) -int a[]={0,1,2}; // Initialized array (or a[3]={0,1,2}; ) -int a[2][2]={{1,2},{4,5}}; // Array of array of ints -char s[]="hello"; // String (6 elements including '\0') -std::string s = "Hello" // Creates string object with value "Hello" -std::string s = R"(Hello -World)"; // Creates string object with value "Hello\nWorld" -int* p; // p is a pointer to (address of) int -char* s="hello"; // s points to unnamed array containing "hello" -void* p=nullptr; // Address of untyped memory (nullptr is 0) -int& r=x; // r is a reference to (alias of) int x -enum weekend {SAT,SUN}; // weekend is a type with values SAT and SUN -enum weekend day; // day is a variable of type weekend -enum weekend{SAT=0,SUN=1}; // Explicit representation as int -enum {SAT,SUN} day; // Anonymous enum -enum class Color {Red,Blue};// Color is a strict type with values Red and Blue -Color x = Color::Red; // Assign Color x to red -typedef String char*; // String s; means char* s; -const int c=3; // Constants must be initialized, cannot assign to -const int* p=a; // Contents of p (elements of a) are constant -int* const p=a; // p (but not contents) are constant -const int* const p=a; // Both p and its contents are constant -const int& cr=x; // cr cannot be assigned to change x -int8_t,uint8_t,int16_t, -uint16_t,int32_t,uint32_t, -int64_t,uint64_t // Fixed length standard types -auto it = m.begin(); // Declares it to the result of m.begin() -auto const param = config["param"]; - // Declares it to the const result -auto& s = singleton::instance(); - // Declares it to a reference of the result -``` - -## STORAGE Classes - -```cpp -int x; // Auto (memory exists only while in scope) -static int x; // Global lifetime even if local scope -extern int x; // Information only, declared elsewhere -``` - -## Statements - -```cpp -x=y; // Every expression is a statement -int x; // Declarations are statements -; // Empty statement -{ // A block is a single statement - int x; // Scope of x is from declaration to end of block -} -if (x) a; // If x is true (not 0), evaluate a -else if (y) b; // If not x and y (optional, may be repeated) -else c; // If not x and not y (optional) - -while (x) a; // Repeat 0 or more times while x is true - -for (x; y; z) a; // Equivalent to: x; while(y) {a; z;} - -for (x : y) a; // Range-based for loop e.g. - // for (auto& x in someList) x.y(); - -do a; while (x); // Equivalent to: a; while(x) a; - -switch (x) { // x must be int - case X1: a; // If x == X1 (must be a const), jump here - case X2: b; // Else if x == X2, jump here - default: c; // Else jump here (optional) -} -break; // Jump out of while, do, or for loop, or switch -continue; // Jump to bottom of while, do, or for loop -return x; // Return x from function to caller -try { a; } -catch (T t) { b; } // If a throws a T, then jump here -catch (...) { c; } // If a throws something else, jump here -``` - -## Functions - -```cpp -int f(int x, int y); // f is a function taking 2 ints and returning int -void f(); // f is a procedure taking no arguments -void f(int a=0); // f() is equivalent to f(0) -f(); // Default return type is int -inline f(); // Optimize for speed -f() { statements; } // Function definition (must be global) -T operator+(T x, T y); // a+b (if type T) calls operator+(a, b) -T operator-(T x); // -a calls function operator-(a) -T operator++(int); // postfix ++ or -- (parameter ignored) -extern "C" {void f();} // f() was compiled in C -``` - -Function parameters and return values may be of any type. A function must either be declared or defined before -it is used. It may be declared first and defined later. Every program consists of a set of a set of global variable -declarations and a set of function definitions (possibly in separate files), one of which must be: - -```cpp -int main() { - ios_base::sync_with_stdio(false); // for fast input and output - cin.tie(NULL); -statements... } // or -int main(int argc, char* argv[]) { statements... } -``` - -`argv` is an array of `argc` strings from the command line. -By convention, `main` returns status `0` if successful, `1` or higher for errors. - -Functions with different parameters may have the same name (overloading). Operators except `::` `.` `.*` `?:` may be overloaded. -Precedence order is not affected. New operators may not be created. - -## Expressions - -Operators are grouped by precedence, highest first. Unary operators and assignment evaluate right to left. All -others are left to right. Precedence does not affect order of evaluation, which is undefined. There are no run time -checks for arrays out of bounds, invalid pointers, etc. - -```cpp -T::X // Name X defined in class T -N::X // Name X defined in namespace N -::X // Global name X - -t.x // Member x of struct or class t -p-> x // Member x of struct or class pointed to by p -a[i] // i'th element of array a -f(x,y) // Call to function f with arguments x and y -T(x,y) // Object of class T initialized with x and y -x++ // Add 1 to x, evaluates to original x (postfix) -x-- // Subtract 1 from x, evaluates to original x -typeid(x) // Type of x -typeid(T) // Equals typeid(x) if x is a T -dynamic_cast< T>(x) // Converts x to a T, checked at run time. -static_cast< T>(x) // Converts x to a T, not checked -reinterpret_cast< T>(x) // Interpret bits of x as a T -const_cast< T>(x) // Converts x to same type T but not const - -sizeof x // Number of bytes used to represent object x -sizeof(T) // Number of bytes to represent type T -++x // Add 1 to x, evaluates to new value (prefix) ---x // Subtract 1 from x, evaluates to new value -~x // Bitwise complement of x -!x // true if x is 0, else false (1 or 0 in C) --x // Unary minus -+x // Unary plus (default) -&x // Address of x -*p // Contents of address p (*&x equals x) -new T // Address of newly allocated T object -new T(x, y) // Address of a T initialized with x, y -new T[x] // Address of allocated n-element array of T -delete p // Destroy and free object at address p -delete[] p // Destroy and free array of objects at p -(T) x // Convert x to T (obsolete, use .._cast(x)) - -x * y // Multiply -x / y // Divide (integers round toward 0) -x % y // Modulo (result has sign of x) - -x + y // Add, or \&x[y] -x - y // Subtract, or number of elements from *x to *y -x << y // x shifted y bits to left (x * pow(2, y)) -x >> y // x shifted y bits to right (x / pow(2, y)) - -x < y // Less than -x <= y // Less than or equal to -x > y // Greater than -x >= y // Greater than or equal to - -x & y // Bitwise and (3 & 6 is 2) -x ^ y // Bitwise exclusive or (3 ^ 6 is 5) -x | y // Bitwise or (3 | 6 is 7) -x && y // x and then y (evaluates y only if x (not 0)) -x || y // x or else y (evaluates y only if x is false (0)) -x = y // Assign y to x, returns new value of x -x += y // x = x + y, also -= *= /= <<= >>= &= |= ^= -x ? y : z // y if x is true (nonzero), else z -throw x // Throw exception, aborts if not caught -x , y // evaluates x and y, returns y (seldom used) -``` - -## Classes - -```cpp -class T { // A new type -private: // Section accessible only to T's member functions -protected: // Also accessible to classes derived from T -public: // Accessible to all - int x; // Member data - void f(); // Member function - void g() {return;} // Inline member function - void h() const; // Does not modify any data members - int operator+(int y); // t+y means t.operator+(y) - int operator-(); // -t means t.operator-() - T(): x(1) {} // Constructor with initialization list - T(const T& t): x(t.x) {}// Copy constructor - T& operator=(const T& t) - {x=t.x; return *this; } // Assignment operator - ~T(); // Destructor (automatic cleanup routine) - explicit T(int a); // Allow t=T(3) but not t=3 - T(float x): T((int)x) {}// Delegate constructor to T(int) - operator int() const - {return x;} // Allows int(t) - friend void i(); // Global function i() has private access - friend class U; // Members of class U have private access - static int y; // Data shared by all T objects - static void l(); // Shared code. May access y but not x - class Z {}; // Nested class T::Z - typedef int V; // T::V means int -}; -void T::f() { // Code for member function f of class T - this->x = x;} // this is address of self (means x=x;) -int T::y = 2; // Initialization of static member (required) -T::l(); // Call to static member -T t; // Create object t implicit call constructor -t.f(); // Call method f on object t - -struct T { // Equivalent to: class T { public: - virtual void i(); // May be overridden at run time by derived class - virtual void g()=0; }; // Must be overridden (pure virtual) -class U: public T { // Derived class U inherits all members of base T - public: - void g(int) override; }; // Override method g -class V: private T {}; // Inherited members of T become private -class W: public T, public U {}; - // Multiple inheritance -class X: public virtual T {}; - // Classes derived from X have base T directly -``` - -All classes have a default copy constructor, assignment operator, and destructor, which perform the -corresponding operations on each data member and each base class as shown above. There is also a default no-argument -constructor (required to create arrays) if the class has no constructors. Constructors, assignment, and -destructors do not inherit. - -## Templates - -```cpp -template T f(T t);// Overload f for all types -template class X {// Class with type parameter T - X(T t); }; // A constructor -template X::X(T t) {} - // Definition of constructor -X x(3); // An object of type "X of int" -template - // Template with default parameters -``` - -## Namespaces - -```cpp -namespace N {class T {};} // Hide name T -N::T t; // Use name T in namespace N -using namespace N; // Make T visible without N:: -``` - -## `memory` (dynamic memory management) - -```cpp -#include // Include memory (std namespace) -shared_ptr x; // Empty shared_ptr to a integer on heap. Uses reference counting for cleaning up objects. -x = make_shared(12); // Allocate value 12 on heap -shared_ptr y = x; // Copy shared_ptr, implicit changes reference count to 2. -cout << *y; // Dereference y to print '12' -if (y.get() == x.get()) { // Raw pointers (here x == y) - cout << "Same"; -} -y.reset(); // Eliminate one owner of object -if (y.get() != x.get()) { - cout << "Different"; -} -if (y == nullptr) { // Can compare against nullptr (here returns true) - cout << "Empty"; -} -y = make_shared(15); // Assign new value -cout << *y; // Dereference x to print '15' -cout << *x; // Dereference x to print '12' -weak_ptr w; // Create empty weak pointer -w = y; // w has weak reference to y. -if (shared_ptr s = w.lock()) { // Has to be copied into a shared_ptr before usage - cout << *s; -} -unique_ptr z; // Create empty unique pointers -unique_ptr q; -z = make_unique(16); // Allocate int (16) on heap. Only one reference allowed. -q = move(z); // Move reference from z to q. -if (z == nullptr){ - cout << "Z null"; -} -cout << *q; -shared_ptr r; -r = dynamic_pointer_cast(t); // Converts t to a shared_ptr - -``` - -## `math.h`, `cmath` (floating point math) - -```cpp -#include // Include cmath (std namespace) -sin(x); cos(x); tan(x); // Trig functions, x (double) is in radians -asin(x); acos(x); atan(x); // Inverses -atan2(y, x); // atan(y/x) -sinh(x); cosh(x); tanh(x); // Hyperbolic sin, cos, tan functions -exp(x); log(x); log10(x); // e to the x, log base e, log base 10 -pow(x, y); sqrt(x); // x to the y, square root -ceil(x); floor(x); // Round up or down (as a double) -fabs(x); fmod(x, y); // Absolute value, x mod y -``` - -## `assert.h`, `cassert` (Debugging Aid) - -```cpp -#include // Include iostream (std namespace) -assert(e); // If e is false, print message and abort -#define NDEBUG // (before #include ), turn off assert -``` - -## `iostream.h`, `iostream` (Replaces `stdio.h`) - -```cpp -#include // Include iostream (std namespace) -cin >> x >> y; // Read words x and y (any type) from stdin -cout << "x=" << 3 << endl; // Write line to stdout -cerr << x << y << flush; // Write to stderr and flush -c = cin.get(); // c = getchar(); -cin.get(c); // Read char -cin.getline(s, n, '\n'); // Read line into char s[n] to '\n' (default) -if (cin) // Good state (not EOF)? - // To read/write any type T: -istream& operator>>(istream& i, T& x) {i >> ...; x=...; return i;} -ostream& operator<<(ostream& o, const T& x) {return o << ...;} -``` - -## `fstream.h`, `fstream` (File I/O works like `cin`, `cout` as above) - - -```cpp -#include // Include filestream (std namespace) -ifstream f1("filename"); // Open text file for reading -if (f1) // Test if open and input available - f1 >> x; // Read object from file -f1.get(s); // Read char or line -f1.getline(s, n); // Read line into string s[n] -ofstream f2("filename"); // Open file for writing -if (f2) f2 << x; // Write to file -``` - -## `string` (Variable sized character array) - -```cpp -#include // Include string (std namespace) -string s1, s2="hello"; // Create strings -s1.size(), s2.size(); // Number of characters: 0, 5 -s1 += s2 + ' ' + "world"; // Concatenation -s1 == "hello world" // Comparison, also <, >, !=, etc. -s1[0]; // 'h' -s1.substr(m, n); // Substring of size n starting at s1[m] -s1.c_str(); // Convert to const char* -s1 = to_string(12.05); // Converts number to string -getline(cin, s); // Read line ending in '\n' -``` - -## `vector` (Variable sized array/stack with built in memory allocation) - -```cpp -#include // Include vector (std namespace) -vector a(10); // a[0]..a[9] are int (default size is 0) -vector b{1,2,3}; // Create vector with values 1,2,3 -a.size(); // Number of elements (10) -a.push_back(3); // Increase size to 11, a[10]=3 -a.back()=4; // a[10]=4; -a.pop_back(); // Decrease size by 1 -a.front(); // a[0]; -a[20]=1; // Crash: not bounds checked -a.at(20)=1; // Like a[20] but throws out_of_range() -for (int& p : a) - p=0; // C++11: Set all elements of a to 0 -for (vector::iterator p=a.begin(); p!=a.end(); ++p) - *p=0; // C++03: Set all elements of a to 0 -vector b(a.begin(), a.end()); // b is copy of a -vector c(n, x); // c[0]..c[n-1] init to x -T d[10]; vector e(d, d+10); // e is initialized from d -``` - -## `deque` (Array stack queue) - -`deque` is like `vector`, but also supports: - -```cpp -#include // Include deque (std namespace) -a.push_front(x); // Puts x at a[0], shifts elements toward back -a.pop_front(); // Removes a[0], shifts toward front -``` - -## `utility` (pair) - -```cpp -#include // Include utility (std namespace) -pair a("hello", 3); // A 2-element struct -a.first; // "hello" -a.second; // 3 -``` - -## `map` (associative array - usually implemented as binary search trees - avg. time complexity: O(log n)) - -```cpp -#include // Include map (std namespace) -map a; // Map from string to int -a["hello"] = 3; // Add or replace element a["hello"] -for (auto& p:a) - cout << p.first << p.second; // Prints hello, 3 -a.size(); // 1 -``` - -## `unordered_map` (associative array - usually implemented as hash table - avg. time complexity: O(1)) - -```cpp -#include // Include map (std namespace) -unordered_map a; // Map from string to int -a["hello"] = 3; // Add or replace element a["hello"] -for (auto& p:a) - cout << p.first << p.second; // Prints hello, 3 -a.size(); // 1 -``` - -## `set` (store unique elements - usually implemented as binary search trees - avg. time complexity: O(log n)) - -```cpp -#include // Include set (std namespace) -set s; // Set of integers -s.insert(123); // Add element to set -if (s.find(123) != s.end()) // Search for an element - s.erase(123); -cout << s.size(); // Number of elements in set -``` - -## `unordered_set` (store unique elements - usually implemented as a hash set - avg. time complexity: O(1)) - -```cpp -#include // Include set (std namespace) -unordered_set s; // Set of integers -s.insert(123); // Add element to set -if (s.find(123) != s.end()) // Search for an element - s.erase(123); -cout << s.size(); // Number of elements in set -``` - -## `algorithm` (A collection of 60 algorithms on sequences with iterators) - -```cpp -#include // Include algorithm (std namespace) -min(x, y); max(x, y); // Smaller/larger of x, y (any type defining <) -swap(x, y); // Exchange values of variables x and y -sort(a, a+n); // Sort array a[0]..a[n-1] by < -sort(a.begin(), a.end()); // Sort vector or deque -reverse(a.begin(), a.end()); // Reverse vector or deque -``` - -## `chrono` (Time related library) -```cpp -#include // Include chrono -using namespace std::chrono; // Use namespace -auto from = // Get current time_point - high_resolution_clock::now(); -// ... do some work -auto to = // Get current time_point - high_resolution_clock::now(); -using ms = // Define ms as floating point duration - duration; - // Compute duration in milliseconds -cout << duration_cast(to - from) - .count() << "ms"; -``` - -## `thread` (Multi-threading library) -```cpp -#include // Include thread -unsigned c = - hardware_concurrency(); // Hardware threads (or 0 for unknown) -auto lambdaFn = [](){ // Lambda function used for thread body - cout << "Hello multithreading"; -}; -thread t(lambdaFn); // Create and run thread with lambda -t.join(); // Wait for t finishes - -// --- shared resource example --- -mutex mut; // Mutex for synchronization -condition_variable cond; // Shared condition variable -const char* sharedMes // Shared resource - = nullptr; -auto pingPongFn = // thread body (lambda). Print someone else's message - [&](const char* mes){ - while (true){ - unique_lock lock(mut);// locks the mutex - do { - cond.wait(lock, [&](){ // wait for condition to be true (unlocks while waiting which allows other threads to modify) - return sharedMes != mes; // statement for when to continue - }); - } while (sharedMes == mes); // prevents spurious wakeup - cout << sharedMes << endl; - sharedMes = mes; - lock.unlock(); // no need to have lock on notify - cond.notify_all(); // notify all condition has changed - } - }; -sharedMes = "ping"; -thread t1(pingPongFn, sharedMes); // start example with 3 concurrent threads -thread t2(pingPongFn, "pong"); -thread t3(pingPongFn, "boing"); -``` - -## `future` (thread support library) -```cpp -#include // Include future -function fib = // Create lambda function - [&](int i){ - if (i <= 1){ - return 1; - } - return fib(i-1) - + fib(i-2); - }; -future fut = // result of async function - async(launch::async, fib, 4); // start async function in other thread -// do some other work -cout << fut.get(); // get result of async function. Wait if needed. -``` diff --git a/C++/#include - -using namespace std; - -int main(){ - int testCase; - cin>>testCase; - while(testCase-->0){ - int n; - cin>>n; - int v[n],fin[n]; - for(int i=0;i>v[i]; - fin[i]=i+1; - } - for(int j=n-1;j>=0;j--){ - if(v[j]!=0){ - int x=fin[j-v[j]]; - for(int k=j-v[j];k -using namespace std; -string S; -int main() -{ - cin>>S; - int a=0,b=0,c=0; - map,int>mp; - long ans=0; - mp[make_tuple(0,0,0)]=1; - for(char d:S) - { - if(d=='A')a++; - else if(d=='B')b++; - else c++; - int mn=min({a,b,c}); - ans+=mp[make_tuple(a-mn,b-mn,c-mn)]++; - } - cout< -using namespace std; - -int main() { - int t,n,s; - cin>>t; - while(t--) - { - cin>>n; - //s=n/3; - if(n%3!=0) - { - cout<<3 - (n%3)< -using namespace std; - -int main() { - int t,a,b,c; - cin>>t; - while(t--) - { - cin>>a>>b>>c; - - if(b>=a && b>=c) // since b is the atmost condition - cout<<"YES\n"; - else - cout<<"NO\n"; - - - } - return 0; -} - -``` - diff --git a/C++/AgeLimit.cpp b/C++/AgeLimit.cpp deleted file mode 100644 index 1afa15f..0000000 --- a/C++/AgeLimit.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -using namespace std; - -int main() { - - int t,x,y,A; - cin>>t; - for(int i=0;i>x>>y>>A; - - if(A>=x && A -using namespace std; - -void bfs(vector> &adjList,int source,int N){ - vector visited(N,false); - - queue q; - visited[source]=true; - q.push(source); - - while(!q.empty()){ - int currentNode=q.front(); - cout<<"Visited: "<> adjList(N); - - adjList[0].push_back(1); - adjList[0].push_back(2); - adjList[0].push_back(4); - - adjList[1].push_back(3); - adjList[2].push_back(3); - adjList[3].push_back(4); - adjList[3].push_back(5); - - bfs(adjList,0,N); - -} diff --git a/C++/Balanced1Tree.cpp b/C++/Balanced1Tree.cpp deleted file mode 100644 index 8bdfd45..0000000 --- a/C++/Balanced1Tree.cpp +++ /dev/null @@ -1,166 +0,0 @@ -//https://www.codechef.com/submit/B01T -#include -using namespace std; -#define mod (ll)(998244353) -#define pii pair -#define vi vector -// #define v vector -#define vc vector -#define vvi vector> -#define vpii vector< pii > -#define vvpii vector >> -#define f first -#define s second -#define pb(x) push_back(x) -#define pf(x) push_front(x) -#define mp(x, y) make_pair(x, y) -#define all(x) x.begin(), x.end() -#define print(vec, l, r) \ - for (int i = l; i <= r; i++) \ - cout << vec[i] << " "; \ - cout << endl; -#define forf(i, a, b) for (ll i = (a); i < (b); i++) -#define forr(i, a, b) for (ll i = (a); i > (b); i -= 1) -#define input(vec, N) for (int i = 0; i < (N); i++) cin >> vec[i]; -typedef long long ll; -#define ld long double -const int N = (2e5+20); -const int M = (1e6+20); -const int MAXN = 2e6+12; -const ll INF = 2e18+90; -#define BLOCK 555 - -typedef unsigned long long ull; -typedef long double lld; - -// #include //required -// #include //required -// using namespace __gnu_pbds; //required -// template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; - - -// s.find_by_order(k); returns the (k+1)th smallest element -// s.order_of_key(k); returns the number of elements in s strictly less than k - - - -long long binpow(long long a, long long b, long long m = mod) { - a %= m; - long long res = 1; - while (b > 0) { - if (b & 1) - res = res * a % m; - a = a * a % m; - b >>= 1; - } - return res; -} - -#define no cout<<"NO"<>n; - - int a[n+2]; - forf(i,1,n+1) cin>>a[i]; - - vvi adj(n+2); - - queue < int > q; - vi deg(n+2,0); - - forf(i,1,n){ - int u,v; - cin>>u>>v; - - adj[u].pb(v); - adj[v].pb(u); - deg[u]++; - deg[v]++; - } - - int rem = 0; - - forf(i,1,n+1){ - if(a[i]) rem++; - else rem--; - - if(adj[i].size() == 1 && i>1){ - q.push(i); - } - } - - vi mark(n+2,0); - set < int > s; - - while(q.size()){ - - if(!rem) break; - - int v = q.front(); - //cout<1 && deg[x]==1){ - q.push(x); - } - } - - } - - cout<> T; - int t=1; - // bfs(); - // calc(); - // sieve(N-5); - // calc(); - while (t<=T) { - //cout<<"Case #"< -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while(t--) - { - int n,k; - cin>>n>>k; - if (n==1 && k==1) - { - cout<<"yes"<=(k*(k+1))/2) - { - cout<<"YES"< -using namespace std; - -int main() { - int a , c ; - cin >> a >> c; - - int y = 0 ; - - while (!(a > c)) { - a *= 3; - c *= 2; - y++; - } - cout << y << endl; - - - -} diff --git a/C++/Black & White Ring Game.cpp b/C++/Black & White Ring Game.cpp deleted file mode 100644 index 4380337..0000000 --- a/C++/Black & White Ring Game.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include -using namespace std; -#define mp make_pair -#define f first -#define mt make_tuple -#define s second -#define ll long long -#define NO cout << "NO" << '\n' -#define YES cout << "YES" << '\n' -#define rep(i, a, b) for(int i = a; i < (b); ++i) -typedef pair pii; -typedef vector vi; -typedef map mii; -class comp{ -public: - bool operator()(pair&t,pair&c){ - return t.f > c.f; - } -}; -class comp_2{ -public: - bool operator()(pair&t,pair&c){ - return t.s > c.s; - } -}; -int main() { - int test; - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cin >> test; - rep(i, 0, test) { - int n; - cin >> n; - if (n==1){ - cout << "Bob" << '\n'; - continue; - } - vi arr(n); - rep(j,0,n) { - cin >> arr[j]; - } - int dif = 0; - int one = 0; - int z = 0; - if (arr[0]==arr[n-1]){ - if (arr[0]){ - one++; - } else { - z++; - } - } - int p = 1; - while (p < n){ - if (arr[p]==arr[p-1]){ - if(arr[p]){ - one++; - } else { - z++; - } - } - p++; - } - dif = min(z,one); - if (dif%2==0){ - cout << "Bob" << '\n'; - } else { - cout << "Alice" << '\n'; - } - } -} - \ No newline at end of file diff --git a/C++/Black and White Ring Game b/C++/Black and White Ring Game deleted file mode 100644 index dd323fa..0000000 --- a/C++/Black and White Ring Game +++ /dev/null @@ -1,28 +0,0 @@ -#include -using namespace std; -#define int long long -int m,a[100001],s1,s2,s; -void solve(){ - cin>>m; - s1=0;s2=0,s=0; - for(int i=1;i<=m;++i){ - cin>>a[i]; - s1+=a[i]==0; - s2+=a[i]==1;} - - for(int i=1;i<=m;++i){ - if(i==1) s+=(a[1]==a[m]); - else s+=(a[i]==a[i-1]); - } - - s-=abs(s1-s2); - cout<<(s%4 ==0?"Bob":"Alice")<>p; - while(p--) solve(); - return 0; -} diff --git a/C++/Brutal-Xors.cpp b/C++/Brutal-Xors.cpp deleted file mode 100644 index 208bb0b..0000000 --- a/C++/Brutal-Xors.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -using namespace std; -typedef long long int ll; -const int N=1e9+7; - -int main(){ - - int t; - cin>>t; - while(t--){ - ll n,ans,y,j; - cin>>n; - ll x=sqrt(n); - //j=n; - y=__builtin_popcountll(n); - - if(n==1)ans=1; - else if(n==2)ans=2; - else{ - if(y==1)ans=(2*n-1)%N; - else { - ll x=log2(n); - ans=pow(2,x+1); - ans=ans%N; - } - } - cout< -void main(){ - int *a,i,j,t,n; - printf("Size of Array : "); - scanf("%d",&n); - printf("Give Array Elements: "); - for(i=0;i *(a+j)){ - t = *(a+i);*(a+i) = *(a+j); - *(a+j) = t; - } - } - } - printf("Sorted array is: "); - for(i=0;i -#include - -#define int long long - -using namespace std; - -int a[3],s; -void solution(){ - s=0; - cin>>a[0]>>a[1]>>a[2]; - for(int i=0; i<3; i++){ - if(a[i]!=0){ - a[i]--; - s++; - } - } - for(int i=0; i<3; i++) - for(int j=i+1; j<3; j++) - if(a[i]>a[j]) - swap(a[i], a[j]); - - if(a[0]>=2){ - cout<=2?s+2:s+1)<>t; - - while(t--){ - solution(); - } - return 0; -} diff --git a/C++/CONFCAT.cpp b/C++/CONFCAT.cpp deleted file mode 100644 index ce0e444..0000000 --- a/C++/CONFCAT.cpp +++ /dev/null @@ -1,60 +0,0 @@ -//Problem link : -> https://www.codechef.com/problems/CONFCAT -//Difficulty Rating -> Difficulty Rating:1488 (Starters 59 -Recent Contest) - - - - -//Code: - -#include -#define int long long -using namespace std; - - -signed main() { - - int t; - cin>>t; - while(t--) { - - int n; - cin>>n; - - int arr[n]; - for(int i=0;i>arr[i]; - } - vector a,b; - int max = INT_MIN; - int position; - for(int i= 0;imax){ - max = arr[i]; - position =i; - } - } - if(position == 0){ - cout<< -1 < -using namespace std; - -int main() { - int t,n,k,s; - cin>>t; - while(t--) - { - cin>>n>>k; - s = (n/k)*(n/k); // it is important to note we should use not (n*n)*/(k*k) since it is not simply area division - cout< -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while(t--) - { - float x1,x2,y1,y2; - cin>>x1>>x2>>y1>>y2; - float c1=0,c2=0; - c1=y1/x1; - c2=y2/x2; - if(c1>c2) - { - cout<<"1"<c1) - { - cout<<"-1"< -#include -#include -#include -using namespace std; - - -int main() -{ char top[10],bottom[10],fr[10],bk[10],left[10],right[10]; - long int T; - cin>>T; - while(T--) - { - cin>>fr>>bk>>left>>right>>top>>bottom; - if(strcmp(fr,top)==0) - { - if(strcmp(left,fr)==0||strcmp(right,fr)==0) - { - cout<<"YES"< -using namespace std; -int main(){ - int j,s,m,ans; - cin>>j>>s>>m; - ans=(m-j)/s; - if(ans%2==0){ - cout<<"Lucky Chef"< -using namespace std; - -int main() { - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - int ans = 0; - int x=1; - while(x!=n){ - if(x==1){ - ans += n*n; - x++; - } - else if(x%2!=0){ - ans += (n-x+1)*(n-x+1); - x++; - } - else { - x++; - } - } - if(n%2==0) { - cout< -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while(t--) - { - int n; - cin>>n; - if(n==2010||n==2015||n==2016||n==2016||n==2017||n==2019) - { - cout<<"HOSTED"< -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while(t--){ - int a,b; - cin>>a>>b; - int ans=0; - ans=a+b; - if(ans<3) - { - cout<<"1"<=3 && ans<=10) - { - cout<<"2"<=11 && ans<=60) - { - cout<<"3"< -using namespace std; - -#define int long long int -#define ld long double -#define pb push_back -#define sp(x,y) fixed< -#define vvi vector> -#define vpi vector> -#define vvpi vector>> -#define inf 9223372036854775807 -const int mod = 998244353; -const int MAX = 5e5+5; - -int32_t main() { -ios::sync_with_stdio(0);cout.tie(0);cin.tie(0); - int t=1; - cin>>t; - while(t--){ - int n; - cin>>n; - vectorv(n); - int mx=-1e8,mxind=-1; - for(int i=0;i>v[i]; - if(mxx,y; - - mapmpx,mpy; -for(int i=0;i -int main() -{ - int t; - std::cin >> t; - while (t--) - { - int n, x, y; - std::cin >> n >> x >> y; - int m = 100006; - for (int i = 0; i <= n; i++) - { - for (int j = 0; j <= n; j++) - { - int k = 100 * j + 4 * i; - if (k >= n) - { - m = std::min(m, i * y + j * x); - } - } - } - std::cout << m << std::endl; - } -} diff --git a/C++/Convert Binary Number to Decimal.cpp b/C++/Convert Binary Number to Decimal.cpp deleted file mode 100644 index b6ebe1d..0000000 --- a/C++/Convert Binary Number to Decimal.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include - -int convert(long long); - -int main() { - long long n; - printf("Enter a binary number: "); - scanf("%lld", &n); - printf("%lld in binary = %d in decimal", n, convert(n)); - return 0; -} - -int convert(long long n) { - int dec = 0, i = 0, rem; - - while (n!=0) { - rem = n % 10; - n /= 10; - dec += rem * pow(2, i); - ++i; - } - return dec; -} diff --git a/C++/Count_the_holidays.cpp b/C++/Count_the_holidays.cpp deleted file mode 100644 index 7271525..0000000 --- a/C++/Count_the_holidays.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -using namespace std; - -int main() -{ - int t,n; - cin >> t; - while (t--) - { - - cin >> n; - int a[n], c = 8; - for (int i = 0; i < n; i++) - { - cin >> a[i]; - - if(a[i]%7 !=0 && 7- a[i]%7 != 1 ) - { - c++; - } - } - - cout << c << endl; - } - return 0; -} \ No newline at end of file diff --git a/C++/Decimal To Binary Conversion.cpp b/C++/Decimal To Binary Conversion.cpp deleted file mode 100644 index ebe7208..0000000 --- a/C++/Decimal To Binary Conversion.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -using namespace std; -int main() -{ - int decimal, binary = 0, mul = 1, rem; - cout << "Enter the Decimal Number: "; - cin >> decimal; - while (decimal > 0) - { - rem = decimal % 2; - binary = binary + (rem * mul); - mul = mul * 10; - decimal = decimal / 2; - } - cout << "\nEquivalent Binary Value: " << binary; - cout << endl; - return 0; -} \ No newline at end of file diff --git a/C++/Decomposition_Reaction.cpp b/C++/Decomposition_Reaction.cpp deleted file mode 100644 index 996852f..0000000 --- a/C++/Decomposition_Reaction.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#define ll long long int -#define int long long -#define loop(i, x, n) for (int i = x; i < n; i++) -#define rloop(i, x, n) for (int i = n - 1; i >= x; i--) -#define vi vector -#define vvi vector> -#define pb push_back -#define mod 1000000007 -#define pr(x) {cout<>n>>m; - int arr[n+1]; - arr[0]=0; - for(int i=1; i<=n; i++) cin>>arr[i]; - map>> map; - for(int i=0; i>reactant>>x; - vector> v; - for(int j=0; j>w>>product; - v.push_back(make_pair(w, product)); - } - map[reactant]=v; - } - for(auto it:map) - { - int lhs=it.first; - for(auto i:it.second) - { - arr[i.second]=1LL*(arr[i.second] + i.first*arr[lhs])%mod; - } - arr[lhs]=0; - } - loop(i,1,n+1) cout< -using namespace std; - -typedef long long int lg; -void check() -{ - lg A,B,C,X,Y,Z; - cin>>A>>B>>C>>X>>Y>>Z; - lg dif= max({X-A,Y-B,Z-C}); - if(dif + A + B + C >(X+Y+Z)/2) - cout<<"YES\n"; - else - cout<<"NO\n"; -} -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - lg solve; - for(cin >> solve;solve--;) - check(); -} diff --git a/C++/Equal_LIS.cpp b/C++/Equal_LIS.cpp deleted file mode 100644 index 839a766..0000000 --- a/C++/Equal_LIS.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -using namespace std; -const int M=1e9; -typedef long long int ll; -ll power(ll a,ll b){ - ll ans=1; - while(b){ - if(b&1){ - ans=(a*1ll*ans)%M; - } - a=(a*1ll*a)%M; - b>>=1; - - } - return ans; -} -int main(){ - - int t; - cin>>t; - while(t--){ - ll k,n,ans=0;cin>>n; - vectorv;k=(n/2)+(n%2!=0);string s; - if(n==2) cout<<"NO"<<"\n"; - else if(n==4){cout<<"YES"<<"\n"; - cout<<2<<" "<<1<<" "<<4<<" "<<3<<"\n"; - } - else if(n%2==0){ - cout<<"YES"<<"\n"; - for(int i=1;i<=k;i++){ - v.push_back(i); - - } - v.push_back(n);ll y=n-1; - for(int i=k+2;i<=n;i++){ - v.push_back(y);y--; - } - ll i1=n/2;ll i2=i1-2; - swap(v[i1],v[i2]); - for(auto i:v)cout< -using namespace std; - -void fibonacci_series(int num) -{ - int a1 = 0; - int a2 = 1; - for (int i = a1; i <= num; i++) - { - cout << a1 << endl; - int nextterm = a1 + a2; - a1 = a2; - a2 = nextterm; - } -} - -int main() -{ - int n; - cout << "Enter No= "; - cin >> n; - fibonacci_series(n); - return 0; -} diff --git a/C++/Find_the_direction.cpp b/C++/Find_the_direction.cpp deleted file mode 100644 index 8364a00..0000000 --- a/C++/Find_the_direction.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while(t--) - { - int x; - cin>>x; - if(x%4==0) - { - cout<<"North"< -using namespace std; -int gcd(int x,int y){ - if(x%y==0){ - return y; - } - else{ - return gcd(y,x%y); - } -} - -int main() { - // your code goes here - int t; - cin>>t; - for(int j=0;j>a>>b; - if(a>b){ - max=a; - } - else{ - max=b; - } - min=(a+b)-max; - h=gcd(max,min); - l=(a*b)/h; - cout< -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while(t--) - { - int n,x,y; - cin>>n>>x>>y; - int tc=0; - tc=(n+1)*y; - if(tc>=x) - { - cout<<"YES"< -using namespace std; - -int main() -{ - int t; - cin >> t; - while (t--) - { - int x, y, z; - cin >> x >> y >> z; - if (x >= y) - { - cout << "PIZZA" << endl; - } - else if (x >= z) - { - cout << "BURGER" << endl; - } - else - { - cout << "NOTHING" << endl; - } - } - return 0; -} diff --git a/C++/MAXIMUM_SUM.cpp b/C++/MAXIMUM_SUM.cpp deleted file mode 100644 index a34f0fd..0000000 --- a/C++/MAXIMUM_SUM.cpp +++ /dev/null @@ -1,212 +0,0 @@ -// vrintle's solution to Maximum Sum problem: https://www.codechef.com/START60A/problems/MAXIMUM_SUM - -////////////////////////////////////////////////////////////////// -///// // -//// Credits: Rahul Verma (CC @vrintle, CF @BlindingKnight) /// -/// Institution: Delhi Technological University (aka. DCE) //// -// ///// -////////////////////////////////////////////////////////////////// - -#include -#include -#include -using namespace std; -using namespace chrono; -using namespace __gnu_pbds; - -template using pbds = tree, rb_tree_tag, tree_order_statistics_node_update>; -// find_by_order(K): Returns an iterator to the Kth largest element (counting from zero) -// order_of_key (K): Returns the number of items that are strictly smaller than K - -/* - - ~ You don't know the power of the dark side! ~ - -..-..,'".- BM\dF. jM@' !MMM.&^'jjjM#*..`. !*m.F. `..... --`.'^-".^. ._'-". `` `"#.# .]MF. _. __-gg.. jMg. ...... -'......._ j#M' jMf jg_jm..-` .Mf_ ja "` .` `^" ,_ 4g."@!. ...,., -',3&^jCgf ._`"`"'. .` """!. .`^^ ..... .""LTgJf. =/<., -_@#MMQK##-@"^ .. .'QK_. .!$AGz -MM&�$#yF. !-M. .gmMM@! ."q. ..K#MD -ZM#ZM#$. q4M. ..__,,yg_. ^\. ..M0# -A0NWM@. jggp. .,m* .#MMMMM#'.. ' ."M0 -BMM$@" !MM#'.. -*' ."QMMMM#`.. ..^$ -BMMM' .^@#.'` _ ,yy___````. . ` -MMMP ... j. 1.L .""9*qwwwJ,. .. -@@@. . ...P`, .F` .`. .. -0T` .P. . F` :"~~- ._.e.,wyyw..,,.... -yg. ' _g0M0g. .-'`'^`Q$_ -Mf .jMMMMML .`-"0M# -@. . ."MMMM@^ ."". -f . -. ... -. . ._ ... - . . . .. - .. -' ., .., ..,. - `. . ..*. . _ , .p_ .-,'jb. -_ jgg, -'-+..--!.!!!` !' .~. _0MM/.-.-/@. .yyygggMM -M0gyy__________. ^0M' "MM^ ...". `^MMMMMM -MMMMMMMMMMMMMM'. .. . - -*/ - -#define F first -#define S second -#define db double -#define ld long db -#define M 1000000007 -#define pb push_back -#define ll long long -#define lll __int128 -#define vl vector -#define vd vector -#define vld vector -#define vvl vector -#define pl pair -#define pd pair -#define vpl vector -#define vpd vector -#define lld __float128 -#define ull unsigned ll -#define sz(a) ((ll) a.size()) -#define PI 3.141592653589793238 -#define all(v) v.begin(), v.end() -#define each(seq) for(auto e: seq) -#define inf numeric_limits::max() -#define acc(a) accumulate(all(a), 0ll) -#define shuff(a) random_shuffle(all(a)) -#define F0(n, i) for(ll i = 0; i < n; i++) -#define F1(n, i) for(ll i = 1; i <= n; i++) -#define google cout << "Case #" << i << ": "; -#define dbgpr(pr) cout << ' ' << #pr << " {" << pr.F << ',' << pr.S << "} " -#define dbgprs(seq) cout << #seq << " <"; each(seq) { dbgpr(e); } cout << ">\n" -#define dbgarr(seq) cout << #seq << " < "; each(seq) { cout << e << ' '; } cout << ">\n" -#define dbgmtx(mat) cout << #mat << " {\n"; each(mat) { cout << ' '; dbgarr(e); } cout << "}\n" -#define lrot(a, l, r, k) rotate(a.begin() + l, a.begin() + l + (k % (r - l + 1)), a.begin() + r + 1) -#define rrot(a, l, r, k) rotate(a.begin() + l, a.begin() + r + 1 - (k % (r - l + 1)), a.begin() + r + 1) -#define dbgmap(hash) cout << #hash << " { "; each(hash) { cout << e.first << ':' << e.second << ' '; } cout << "}\n" -#define dbgtree(tree) cout << #tree << " {\n"; each(tree) { cout << e.first << ": "; dbgarr(e.second); } cout << "}\n" - -// Debug Template, copied from Mikel_Arteta_8 (https://codeforces.com/blog/entry/68809) -void __print(int x) {cerr << x;} -void __print(long x) {cerr << x;} -void __print(long long x) {cerr << x;} -void __print(unsigned x) {cerr << x;} -void __print(unsigned long x) {cerr << x;} -void __print(unsigned long long x) {cerr << x;} -void __print(float x) {cerr << x;} -void __print(double x) {cerr << x;} -void __print(long double x) {cerr << x;} -void __print(char x) {cerr << '\'' << x << '\'';} -void __print(const char *x) {cerr << '\"' << x << '\"';} -void __print(const string &x) {cerr << '\"' << x << '\"';} -void __print(bool x) {cerr << (x ? "true" : "false");} -template -void __print(const pair &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} -template -void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} -void _print() {cerr << "]\n";} -template -void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} -#ifdef VRINTLE -#define debug(x...) cerr << "[" << #x << "] = ["; _print(x) -#else -#define debug(x...) -#endif -// End of debugging template - -/* ostream& operator<<(ostream& o, const __int128& x) { - if (x == numeric_limits<__int128>::min()) return o << "-170141183460469231731687303715884105728"; - if (x < 0) return o << "-" << -x; - if (x < 10) return o << (char)(x + '0'); - return o << x / 10 << (char)(x % 10 + '0'); -} */ - -ll sieve_size = 0, facto_size = 0; -vector F(facto_size+1); -vector state(sieve_size+1, 1); -// exp() for (N^K)%M is only valid, when N%M != 0, else return 0 -ll exp(ll n,ll k,ll m=M){ll r=1,a=n%m;do{r=k&1?r*a%m:r;a=a*a%m;}while(k/=2);return r;} -ll imod(ll a,ll m=M){return exp(a,m-2,m)%m;} -ll C(ll n,ll r,ll m=M){return r?(F[n]*imod(F[r],m)%m*imod(F[n-r],m)%m)%m:1;} -void facto(ll n=facto_size,ll m=M){F[0]=1;F1(n,i)F[i]=(F[i-1]*i)%m;} -void sieve(ll n=sieve_size){for(ll i=4;i<=n;i+=2)state[i]=0;for(ll i=3;i<=n;i+=2)for(ll j=i*i;j<=n;j+=i)state[j]=0;} -// when floor(-1 / 4) = -1, use this one -templateT fdivf(T a,T b){return a/b-((a^b)<0&&a%b);} - -// taken from https://cp-algorithms.com/algebra/prime-sieve-linear.html -// linear sieve algo - -const int N = 1e6; -vector lp(N + 1); -vector pr; - -void precum() { -for (int i=2; i <= N; ++i) { - if (lp[i] == 0) { - lp[i] = i; - pr.push_back(i); - } - for (int j=0; j < (int)pr.size() && pr[j] <= lp[i] && i*pr[j] <= N; ++j) { - lp[i * pr[j]] = pr[j]; - } -} -} - -void solve() { - ll n; - cin >> n; - vl a(n); - vector cnts(N + 1); - F0(n, i) { - cin >> a[i]; - map cnt; - while(a[i] > 1) { - debug(a[i], lp[a[i]]); - cnt[lp[a[i]]]++; - a[i] /= lp[a[i]]; - } - each(cnt) cnts[e.F].pb({e.S, e.F}); - } - vvl idx(N + 1); - F1(N, i) { - idx[sz(cnts[i])].pb(i); - } - vector cnts_; - for(ll i = N; i >= 1; i--) { - each(idx[i]) cnts_.pb(cnts[e]); - } - swap(cnts_, cnts); - F0(sz(cnts), i) sort(all(cnts[i])); - debug(cnts); - ll ans = 0; - F0(n, i) { - ll k = 1; - debug(sz(cnts)); - while(sz(cnts) && sz(cnts.back()) == 0) cnts.pop_back(); - for(ll i = 0; i < sz(cnts); i++) { - k = k * exp(cnts[i].back().S, cnts[i].back().F) % M; - cnts[i].pop_back(); - } - ans = (ans + k) % M; - } - cout << ans; -} - -int32_t main() { - auto start = high_resolution_clock::now(); - ios_base::sync_with_stdio(false); - cin.tie(NULL); - precum(); - ll t = 1; - cin >> t; - F1(t, i) { - // google - solve(); - cout << '\n'; - } - auto stop = high_resolution_clock::now(); - auto duration = duration_cast(stop - start); - debug(duration.count(), " µs!"); - return 0; -} diff --git a/C++/MagicalDoorsCode.cpp b/C++/MagicalDoorsCode.cpp deleted file mode 100644 index 3cade00..0000000 --- a/C++/MagicalDoorsCode.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include - -#define ll long long - -using namespace std; - -int main() -{ - int t; - cin>>t; - while(t--) - { - string s; - cin>>s; - int ans=0; - if(s[0]=='0')ans=1; - for(int i=1; i -using namespace std; - -int main() -{ - // your code goes here - int t; - cin>>t; - while(t--) - { - int n; - cin>>n; - vector arr; - for(int i=0;i>temp; - arr.push_back(temp); - } - string str; - cin>>str; - if(is_sorted(arr.begin(),arr.end())) - { - cout<<0< arr2=arr; - sort(arr.begin(),arr.end()); - int s=INT_MAX,e=INT_MIN; - for(int i=0;i -#include -#include -#include -#define yes cout<<"yes"<>t; - while(t--) - { - int a,b; - cin>>a>>b; - int maxi = max(a,b); - int mini = min(a,b); - if(maxi%mini == 0) - { - int num = maxi/mini; - if((num&(num-1)) == 0) - yes - else - no - } - else - no - } - return 0; -} diff --git a/C++/Make_Palindrome2.cpp b/C++/Make_Palindrome2.cpp deleted file mode 100644 index 4b57b58..0000000 --- a/C++/Make_Palindrome2.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -using namespace std; -typedef long long int ll; - -int main(){ - - int t; - cin>>t; - while(t--){ - int n1;cin>>n1;string st;cin>>st;string ans=""; - int cnt1=count(st.begin(),st.end(),'1'); - int cnt0=count(st.begin(),st.end(),'0'); - if(cnt0>n1/2){ - while(cnt0--){ - ans+='0'; - } - }else{ - while(cnt1--){ - ans+='1'; - } - } - cout< -using namespace std; - -int main() -{ - int t; - cin >> t; - while (t--) - { - int p, in; - cin >> p >> in; - int un = p - in; - cout << min(in, un) << endl; - } - return 0; -} diff --git a/C++/Maximum SubArray b/C++/Maximum SubArray deleted file mode 100644 index 6a0630d..0000000 --- a/C++/Maximum SubArray +++ /dev/null @@ -1,84 +0,0 @@ -#include -using namespace std; - -#define int long long int -#define ld long double -#define pb push_back -#define sp(x,y) fixed< -#define vvi vector> -#define vpi vector> -#define vvpi vector>> -#define inf 9223372036854775807 -const int mod = 998244353; -const int MAX = 5e5+5; - - -int32_t main() { -ios::sync_with_stdio(0);cout.tie(0);cin.tie(0); - int t=1; - cin>>t; - while(t--){ - int n; - cin>>n; - vectorv(n),w; - int sum=0,mxind=0; - for(int i=0;i>v[i]; - - } - - int m; - cin>>m; - vectorb(m); - for(int i=0;i>b[i]; - if(b[i]>0) - w.pb(b[i]); - - } - - for(int i=0;i0) - v.pb(b[i]); - - } - int ans=(-1e8)-5; - int mxsum=(-1e8)-5; - for(int i=0;i -using namespace std; -//Naive Solution. -int MaxSum(int arr[] , int n) -{ - int res = 0 ; - for(int i = 0 ; i -typedef long long ll; - -#define mod 1000000007 -#define inf 1e9 -#define rep(i,n) for(int i=0;i>tt;while(tt--) -#define pb push_back -#define endl "\n" -#define vll vector -#define pi pair -#define all(arr) arr.begin(),arr.end() -using namespace std; -void init_code(){ - #ifndef ONLINE_JUDGE - freopen("input.txt","r",stdin); - freopen("output.txt","w",stdout); - #endif -} - - -void solve(){ - int n; cin>>n; - vector a(n); - for(int i=0;i>a[i]; - - int m; cin>>m; - vector b(m); - for(int i=0;i>b[i]; - - vector tempa= a; - for(int i=0;i0){ - a.push_back(b[i]); - tempa.insert(tempa.begin(),b[i]); - } - } - - long long sum=0, maxsum=INT_MIN; - for(int i=0;i>t; - - while(t--){ - solve(); - } - -} \ No newline at end of file diff --git a/C++/Mean Maximization.cpp b/C++/Mean Maximization.cpp deleted file mode 100644 index a79e068..0000000 --- a/C++/Mean Maximization.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -using namespace std; - -int largest(int arr[], int n) -{ - return *max_element(arr, arr + n); -} -void mean(int arr[], int n, int mx) -{ - float sum = 0; - for (int i = 0; i < n; i++) - sum += arr[i]; - sum = sum - mx; - n = n - 1; - float ans = sum / n; - cout << fixed << setprecision(6) << ans + mx << endl; -} -int main() -{ - int t; - cin >> t; - while (t--) - { - int n; - cin >> n; - int arr[n]; - for (int i = 0; i < n; i++) - { - cin >> arr[i]; - } - int mx = largest(arr, n); - mean(arr, n, mx); - } - return 0; -} diff --git a/C++/Median_Minimization.cpp b/C++/Median_Minimization.cpp deleted file mode 100644 index b044e1d..0000000 --- a/C++/Median_Minimization.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -using namespace std; -typedef long long ll; -typedef vector vi; -typedef pair pi; -#define F first -#define S second -#define PB push_back -#define MP make_pair -#define REP(i,a,b) for (int i = a; i <= b; i++) -void solve(){ - ll n; - cin>>n; - vector a(n); - - for(int i=0;i>a[i]; - } - - sort(a.begin(),a.end()); - - ll mn=a[n/2]-a[n/2-1]; - cout<>t; - while (t--) - { - solve(); - } - return 0; -} diff --git a/C++/Mergesort.cpp b/C++/Mergesort.cpp deleted file mode 100644 index 7f1d7d9..0000000 --- a/C++/Mergesort.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -using namespace std; -const int N = 1e5 + 10; -int a[N]; -// Merges two subarrays of array[]. -// First subarray is L[begin..mid] -// Second subarray is R[mid+1..end] -void merge(int l, int r, int mid) -{ - // merging two sorted array - int l_size = mid - l + 1; - int r_size = r - mid; - int L[l_size + 1], R[r_size + 1]; // extra one ele INT_MAX - - // fill array made above - for (int i = 0; i < l_size; i++) - { - L[i] = a[i + l]; - } - for (int i = 0; i < r_size; i++) - { - R[i] = a[i + mid + 1]; - } - L[l_size] = R[r_size] = INT_MAX; - - int s = 0; - int s2 = 0; - - for (int i = l; i <= r; i++) - { - if (L[s] <= R[s2]) - { - a[i] = L[s]; - s++; - } - else - { - a[i] = R[s2]; - s2++; - } - } -} - -void merge_sort(int l, int r) -{ - if (l == r) - return; // 1 ele only present - int mid = (l + r) / 2; - merge_sort(l, mid); // l se mid ka sort kar diya - merge_sort(mid + 1, r); // mid+1 se r ka sort kar diya - merge(l, r, mid); // sorted array ko merge kardega -} - -int main() -{ - int n; - cin >> n; - for (int i = 0; i < n; i++) - { - cin >> a[i]; - } - merge_sort(0, n - 1); - for (int i = 0; i < n; i++) - { - cout << a[i] << " "; - } - return 0; -} - -// O(N LOG N TO THE BASE 2) diff --git a/C++/Minimum_Colouring.cpp b/C++/Minimum_Colouring.cpp deleted file mode 100644 index 39db975..0000000 --- a/C++/Minimum_Colouring.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include -using namespace std; -#define ll long long -#define fastio() ios_base::sync_with_studio(false);cin.tie(NULL);cout.tie(NULL) -#define fo(i,n) for(ll i=0;in;k pii; -typedef pair pll; -typedef vector vi; -typedef vector vl; -typedef vector vpi; -typedef vector vpl; -typedef vector vvi; -typedef vector vvl; -ll power(ll a,ll b){ - ll ans=1; - while(b){ - if(b&1){ - ans=(ans*1ll*ans); - } - a=(a*1ll*a); - b=(b>>1); - } - return ans; -} -bool cmp(pii &a,pii &b){ - if(a.first==b.first)return b.second>a.second; - return a.first>b.first; -} -bool cmp1(pll &a,pll &b){ - return a.second>t; - - while(t--){ - ll n,m;cin>>n>>m; - ll x1,x2,y1,y2,dist; - ll a[n+1][m+1]; - for(int i=1;i<=n;i++){ - for(int j=1;j<=m;j++)a[i][j]=0; - } - cin>>x1>>y1>>x2>>y2; - a[x1][y1]=1;a[x2][y2]=2; - dist=abs(y1-y2)+abs(x1-x2); - ll d2=(x1-1+y1-1); - if(dist%2){ - for(int i=1;i<=n;i++){ - for(int j=1;j<=m;j++){ - if(a[i][j]==0){ - if(a[1][1]==0){ - if(d2%2==0){ - a[1][1]=1; - }else{ - a[1][1]=2; - } - }else if(j>1){ - if(a[i][j-1]==1)a[i][j]=2; - else a[i][j]=1; - }else if(i-1>=1){ - if(a[i-1][j]==1)a[i][j]=2; - else a[i][j]=1; - } - } - } - } - - }else{ - if(x2+1<=n)a[x2+1][y2]=3; - if(x2-1>=1)a[x2-1][y2]=3; - if(y2-1>=1)a[x2][y2-1]=3; - if(y2+1<=m)a[x2][y2+1]=3; - - for(int i=0;i<=n;i++){ - for(int j=0;j<=m;j++){ - if(a[i][j]==0){ - if(a[1][1]==0){ - if(d2%2==0){ - a[1][1]=1; - }else{ - a[1][1]=2; - } - }else if(j>1){ - if(a[i][j-1]==1)a[i][j]=2; - else a[i][j]=1; - }else if(i-1>=1){ - if(a[i-1][j]==1)a[i][j]=2; - else a[i][j]=1; - } - } - } - } - } - for(int i=1;i<=n;i++){ - for(int j=1;j<=m;j++)cout< -using namespace std; - -int main() { - int t; - cin>>t; - while(t--){ - int n;cin>>n;int a[n]; - for(int i=0;i>a[i]; - for(int i=0;i -#define int long long -using namespace std; -void solve(){ - int n;string s; - cin >> n >> s; - for(int i=0;i> T; - while(T--) solve(); -} - - -[codechef]SINGLEOP2 - -#include -#define int long long -using namespace std; -void solve(){ - int n;string s; - cin >> n >> s; - for(int i=1;i> T; - while(T--) solve(); -} - - - -[codechef]BINARYSUB - -#include -#define int long long -using namespace std; -bool a[100001]; -int dp[100001][2]; -void solve(){ - int n;string s; - cin >> s;n=s.size(); - for(int i=1;i> T; - while(T--) solve(); -} - - - -[codechef]ARRCONS - -#include -#define int long long -using namespace std; -int n,m,s; -long long power(long long b,long long n) { - long long s=1; - while(n) { - if(n%2==1)s=s*b%998244353; - b=b*b%998244353; - n/=2; - } - return s; -} -long long count(int i,int j) { - return ((i/(1<<(j+1)))<> n >> m;s=0; - for(int i=0;i<31;++i) - s=(s+(power(count(m,i),n)<> T; - while(T--) solve(); -} - - - -[codechef]TWOZERO - -#include -#define int long long -#define MOD 1000000007 -using namespace std; -long long power(long long b,long long n) { - long long s=1; - while(n) { - if(n%2==1)s=s*b%MOD; - b=b*b%MOD; - n/=2; - } - return s; -} -long long Inv(int x) { - return power(x,MOD-2); -} -int n,m,s,a[3],b[3]; -void solve(){ - cin >> n >> m; - a[0]=(vector{2,1,-1,-2,-1,1}[n%6]+power(2,n))*Inv(3)%MOD; - a[1]=(vector{-1,1,2,1,-1,-2}[n%6]+power(2,n))*Inv(3)%MOD; - a[2]=(vector{-1,-2,-1,1,2,1}[n%6]+power(2,n))*Inv(3)%MOD; - b[0]=(vector{2,1,-1,-2,-1,1}[m%6]+power(2,m))*Inv(3)%MOD; - b[1]=(vector{-1,1,2,1,-1,-2}[m%6]+power(2,m))*Inv(3)%MOD; - b[2]=(vector{-1,-2,-1,1,2,1}[m%6]+power(2,m))*Inv(3)%MOD; - cout << ((a[0]*b[0]+a[1]*b[1]+a[2]*b[2])%MOD+MOD-1)%MOD << endl; -} -signed main() { - int T;cin >> T; - while(T--) solve(); -} \ No newline at end of file diff --git a/C++/Odds_and_Evens.cpp b/C++/Odds_and_Evens.cpp deleted file mode 100644 index cc48d67..0000000 --- a/C++/Odds_and_Evens.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while(t--) - { - int a,b; - cin>>a>>b; - int ans=0; - ans=a+b; - if(ans%2==0) - { - cout<<"Bob"< -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while(t--) - { - int g1,b1,s1,g2,b2,s2; - cin>>g1>>b1>>s1>>g2>>b2>>s2; - int ans=g1+s1+b1; - int sum=g2+s2+b2; - if(ans>sum) - { - cout<<"1"< -using namespace std; - -int main() -{ - // your code goes here - int t; - cin >> t; - while (t--) - { - int n; - cin >> n; - string s = ""; - char curr = 'a'; - - for (int i = 0; i < n; i++) - { - s += curr; - curr++; - - if (curr == 'z') - curr = 'a'; - } - cout << s << endl; - } - return 0; -} diff --git a/C++/Parallel_Processing.cpp b/C++/Parallel_Processing.cpp deleted file mode 100644 index 668e77f..0000000 --- a/C++/Parallel_Processing.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include -#define ll long long int -#define int long long -#define loop(i, x, n) for (int i = x; i < n; i++) -#define rloop(i, x, n) for (int i = n - 1; i >= x; i--) -#define vi vector -#define pr(x) cout<>n; - vector v; - int sum=0; - loop(i,0,n) - { - int ele; - cin>>ele; - v.push_back(ele); - sum+=ele; - } - int prefix=0, mini=INT_MAX, minDiff=INT_MAX; - for(int i=0; i> t; - while (t--) - code(); - return 0; -} diff --git a/C++/Penalty_shots.cpp b/C++/Penalty_shots.cpp deleted file mode 100644 index 7754f77..0000000 --- a/C++/Penalty_shots.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -using namespace std; - -int main() { - int t; - cin>>t; - while(t-->0) - { - int goal[10]; - for (int i=0;i<10;i++) - { - cin>>goal[i]; - } - int sum1=0,sum2=0; - for(int i=0;i<9;i=i+2) - { - sum1=sum1+goal[i]; - } - for(int i=1;i<10;i=i+2) - { - sum2=sum2+goal[i]; - } - if (sum1>sum2) - { - cout<<1< -using namespace std; - -int main() { - // your code goes here - int t;cin>>t; - for(;t>0;t--){ - int a,b;cin>>a>>b; - cout< -using namespace std; -bool prime[1000000 + 1]; -vector v; -void SieveOfEratosthenes(int n) -{ - //bool prime[n + 1]; - memset(prime, true, sizeof(prime)); - - for (int p = 2; p * p <= n; p++) - { - // If prime[p] is not changed, - // then it is a prime - if (prime[p] == true) - { - for (int i = p * p; i <= n; i += p) - prime[i] = false; - } - } - for (int p = 2; p <= n; p++) - if (prime[p]) - v.push_back(p); -} -int main() -{ - SieveOfEratosthenes(1000000); - int t,n; - int a[1000001]; - memset(a,0,sizeof(a)); - int s=0; - for(int i=1;i>t; - while(t--) - { - cin>>n; - cout< -using namespace std; - -int main() { - int t; - cin>>t; - while(t--) { - int n; - cin >> n; - int ans = 0; - int a, b; - for (int i = 0; i < n; i++) { - cin >> a >> b; - ans += b-a; - } - cout<<-ans< -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while(t--) - { - int h,x,y,c; - cin>>h>>x>>y>>c; - int tc=x+y/2; - int th=h*tc; - if(th<=c) - { - cout<<"YES"< -#include -int main(){ - int n,m; - printf("\nNumber of rows : "); - scanf("%d",&m); - printf("\nNumber of columns : "); - scanf("%d",&n); - int arr[m][n]; - int i,j; - printf("\nInput the matrix \n"); - for(i = 0; i < m; i++){ - for(j = 0; j < n; j++){ - scanf("%d",&arr[i][j]); - } - } -printf("\nThe Matrix is \n"); -for(i = 0; i < m; i++){ - for(j = 0; j < n; j++){ - printf("%d ",*(*(arr+i)+j)); - } - printf("\n"); - } - printf("\nSpiral Matrix in linear order is : "); - int k = 0, l = 0; - while(k < m && l < n){ - for(i = l; i < n; i++){ - printf("%d ",*(*(arr+k)+i)); - } - k++; - for(i = k; i < m; i++){ - printf("%d ",*(*(arr+i)+(n-1))); - } - n--; - if(k < m){ - for(i = n-1; i >= 0; --i){ - printf("%d ",*(*(arr+(m-1))+i)); - } - m--; - } - if(l < n){ - for(i=m-1; i >= k; i--){ - printf("%d ",*(*(arr+i)+l)); - } - l++; - } - } -return 0; -} diff --git a/C++/Sticks_and_Rectangles.cpp b/C++/Sticks_and_Rectangles.cpp deleted file mode 100644 index 1e20582..0000000 --- a/C++/Sticks_and_Rectangles.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#define int long long -using namespace std; - -void code() -{ - int n, ans=0, cnt=0; - cin>>n; - map m; - for(int i=0; i>e; - m[e]++; - } - for(auto &it:m) - { - if(it.second%2) - { - it.second+=1; - ans++; - } - cnt+=it.second/2; - } - if(cnt%2) ans+=2; - cout<> t; - while (t--) - code(); - return 0; -} diff --git a/C++/Suspense String b/C++/Suspense String deleted file mode 100644 index b189de7..0000000 --- a/C++/Suspense String +++ /dev/null @@ -1,56 +0,0 @@ -#include -using namespace std; - -#define int long long int -#define ld long double -#define pb push_back -#define sp(x,y) fixed< -#define vvi vector> -#define vpi vector> -#define vvpi vector>> -#define inf 9223372036854775807 -const int mod = 998244353; -const int MAX = 5e5+5; - -int32_t main() { -ios::sync_with_stdio(0);cout.tie(0);cin.tie(0); - int t=1; - cin>>t; - while(t--){ - int n; - cin>>n; - string s; - cin>>s; - dequed; - string ans=""; - int i=0,j=n-1; - while(i<=j) - { - string temp1=ans+s[i]; - string temp2=s[i]+ans; - if(temp1>temp2) - ans=temp2; - else - ans=temp1; - i++; - if(i>j) - break; - temp1=ans+s[j]; - temp2=s[j]+ans; - if(temp1 -using namespace std; -#define endl "\n" -typedef long long int ll; -ll mod = 1e9+9; - -/*--------------------------------------functions-------------------------------------------*/ - -ll gcd(ll a, ll b){ // GCD of two numbers - if (b == 0) - return a; - return gcd(b, a % b); -} - -ll lcm(ll a,ll b){ // LCM of two numbers - return ((a*b) / gcd(a,b)); -} - -int arrGCD(vectorarr) //GCD of array/vector -{ - int n = arr.size(); - ll result = arr[0]; - for (int i = 1; i < n; i++) - { - result = gcd(arr[i], result); - - if(result == 1) - { - return 1; - } - } - return result; -} - -ll findlcm(vector arr) // LCM of an array/vector -{ - int n = arr.size(); - ll ans = arr[0]; - - for (int i = 1; i < n; i++) - ans = (((arr[i] * ans)) / - (gcd(arr[i], ans))); - - return ans; -} - -vector> allPossibleSubset(vectorarr, int n) //generates 2^n subsets in vector -{ - vector>ans; - int count = pow(2, n); - - for (int i = 0; i < count; i++) { - vectorx; - for (int j = 0; j < n; j++) { - if ((i & (1 << j)) != 0) - x.push_back(arr[j]); - } - ans.push_back(x); - } - return ans; -} - -void print(vector>ans){ // prints a 2D array / vector - for(int i=0;i> input(int i,int j){ // takes input of a 2D vector - vector>ans; - for(int m=0;mn; - for(int p=0;p> l; - n.push_back(l); - } - ans.push_back(n); - } - return ans; -} - -ll binpow(ll a, ll b){ // longer powers a^b - a%=mod; - ll ans=1; - while(b){ - if(b&1)ans=(ans*a) % mod; - a = (a * a) % mod; - b>>=1; - } - return ans; -} - -bool isPrime(ll n){ // check if a number is prime or not - if(n==1)return false; - for(ll i=2;i*i<=n;++i) - if(n%i==0)return false; - return true; -} - -vector primefactors(int n){ // prime factors of a number - vectorans; - for(int i=2;i*i<=n;++i){ - while(n%i==0){ - ans.push_back(i); - n/=i; - } - } - if(n>1)ans.push_back(n); - return ans; -} - -vector SieveOfEratosthenes(ll n) // primes in range -{ - vectorans; - bool prime[n + 1]; - memset(prime, true, sizeof(prime)); - - for (int p = 2; p * p <= n; p++) - { - - if (prime[p] == true) - { - for (int i = p * p; i <= n; i += p) - prime[i] = false; - } - } - for(ll i=2;i<=n;++i) - if(prime[i])ans.push_back(i); - return ans; -} - -int power(int x, unsigned int y, unsigned int m) // power modulo m -{ - if (y == 0) - return 1; - int p = power(x, y / 2, m) % m; - p = (p * p) % m; - - return (y % 2 == 0) ? p : (x * p) % m; -} - -int modInverse(int a, int m) // inv -{ - int g = gcd(a, m); - if (g != 1)return 0; - else return power(a, m - 2, m); -} - -string to_binary(int n){ - string ans = bitset<64> (n).to_string(); - const auto loc1 = ans.find('1'); - - if(loc1 != string::npos){ - return ans.substr(loc1); - } - return "0"; -} - -vector> findPermutations(vectorarr, int n){ - vector>ans; - sort(arr.begin(), arr.end()); - do { - vectorx(arr.begin(),arr.end()); - ans.push_back(x); - } while (next_permutation(arr.begin(),arr.end())); - return ans; -} - -bool isSubSequence(string str1, string str2){ // if str1 is a subsequence of str2 - int m=str1.size(),n=str2.size(); - int j = 0; - for (int i = 0; i < n && j < m; i++) - if (str1[j] == str2[i]) - j++; - return (j == m); -} - -int lis(vectorarr){ // returns the length of longest increasing sub - int n=arr.size(); - int lis[n]; - lis[0] = 1; - for (int i = 1; i < n; i++) { - lis[i] = 1; - for (int j = 0; j < i; - j++) - if (arr[i] > arr[j] && lis[i] < lis[j] + 1) - lis[i] = lis[j] + 1; - } - return *max_element(lis, lis + n); -} - -int fact(int n){ - if(n==0) - return 1; - int res = 1; - for (int i = 2; i <= n; i++) - res = res * i; - return res; -} - -int nCr(int n, int r){ - return fact(n) / (fact(r) * fact(n - r)); -} - -// cout << "Case #" << google <<": "<< ans << endl; -// google++; - - - -/*------------------------------------main code----------------------------------------------*/ - - -class Node{ -public: - int data; - Node* next; - - Node(int data){ - this->data = data; - this->next = NULL; - } -}; - -void InsertAtHead(Node* &head,int data){ - Node* temp = new Node(data); - temp->next = head; - head = temp; -} - -void PrintLL(Node* &head){ - Node* temp = head; - while(temp != NULL){ - cout << temp->data << " "; - temp = temp->next; - } - cout << endl; -} - - - -int main(){ - ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); - - int tt=1,google=1; - cin >> tt; - while(tt--){ - int n; - cin >> n; - string s,res=""; - cin >> s; - if(n==1)cout << s << endl; - int i=0,j=n-1; - while(j>=i){ - if(s[i]=='0')res = "0" + res; - else res+="1"; - if(s[j]=='0' && i -using namespace std; -#define el "\n"; - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(0); - int t,p1,p2,sp1=0,sp2=0,w,l=0; - cin>>t; - while(t--){ - cin>>p1>>p2; - sp1+=p1; sp2+=p2; - if(sp1>sp2 && (sp1-sp2)>l){ - l=sp1-sp2; - w=1; - } - else if(sp1l){ - l=sp2-sp1; - w=2; - } - } - cout< https://www.codechef.com/problems/E1 -//Difficulty Rating -> Difficulty Rating:1530 (Dynamic Programming) - -//Code: -#include -#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); -using namespace std; - -int dp[10005][1005]; - -int DFS(int x, int y, int n, vector>&a) -{ - if (x<0 || y<0 || x>=n || y>=n) return 0; - - if (dp[x][y]>=0) return dp[x][y]; - - int t; - if (a[x][y]=='P') t=1; - else t=0; - - int f=t+DFS(x-2,y+1, n, a); - int b=t+DFS(x-1,y+2, n, a); - int c=t+DFS(x+1,y+2, n, a); - int d=t+DFS(x+2,y+1, n, a); - - int kq; - kq=max(f, b); - kq=max(kq, c); - kq=max(kq, d); - - dp[x][y]=kq; - return dp[x][y]; - -} - -int main() -{ - faster - int T; - cin >> T; - while (T--) - { - int x, y, n; - cin >> n; - vector< vector > a(n, vector(n)); - - for(int i=0; i> a[i][j]; - if (a[i][j]=='K') {x=i; y=j;} - } - - int kq=DFS(x, y, n, a); - cout << kq << endl; - } -} - - diff --git a/C++/The_old_saint_and_three_questions.cpp b/C++/The_old_saint_and_three_questions.cpp deleted file mode 100644 index 3d4f757..0000000 --- a/C++/The_old_saint_and_three_questions.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while(t--) - { - int a=0,b=0,c=0,d=0; - int i,j; - int arr[3]; - int arr1[3]; - for(i=0;i<3;i++) - { - cin>>arr[i]; - if(arr[i]==0) - { - a++; - } - else if(arr[i]==1) - { - b++; - } - } - for(j=0;j<3;j++) - { - cin>>arr1[j]; - if(arr1[j]==0) - { - c++; - } - else if(arr1[j]==1) - { - d++; - } - } - if (a==c && b==d) - { - cout<<"Pass"< -using namespace std; -typedef long long int ll; -#define pb push_back; -#define wh(k) while(k--) -#define fo(i, c) for (long long(i) = 0; (i) < (c); ++(i)) -typedef vector vi; -typedef vector vst; -typedef vector vfl; -typedef pair ii; -typedef vector> vecpr; -typedef list lis; -typedef stack stk; -typedef queue que; -typedef set seti; -typedef multiset mulset; -typedef unordered_set unoset; -typedef map mapi; -typedef multimap mulmap; -typedef unordered_map unomap; -typedef map mapstr; -typedef map mapvec; -const long long mod = 1e9 + 7; -const long long N = 1e5 + 5; -ll bin_exp(ll a,ll pw) -{ - if(pw == 0) return 1; - ll x = bin_exp(a,(pw/2)); - if(pw%2==0) - { - return (x*x); - } - else return (x*x*a); -} -signed main() -{ - ll t;cin>>t; - while(t--) - { - ll n,k;cin>>n>>k; - ll lim = bin_exp(2,n); - ll ans = (lim-1)*(lim-2); - cout< -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while(t--) - { - int d,l,r; - cin>>d>>l>>r; - if (d>=l && d<=r) - { - cout<<"Take second dose now"<l && d>r) - { - cout<<"Too Late"< -using namespace std; - -void solve() -{ - int n; - cin >> n; - int c = 5; - int zero = 0; - while (n / c > 0) - { - zero += n / c; - c *= 5; - } - cout << zero << endl; -} - -int main() -{ - int t; - cin >> t; - while (t--) - { - solve(); - } - return 0; -} diff --git a/C++/a.exe b/C++/a.exe deleted file mode 100644 index ed6cc9f40b3bd3405b0741853ce13a7db1ed5d2c..0000000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j!w zAsJCfxOFd<+0adPVPL7{v<^O%CeWQ)Tw$^~R8as`75rY@P_0u0CM7g#KG+)x4j5gK z7Xsy1`X9tQeEd8~&0lCMVLY{Eu~f-#14Q|cD|n`j9a`saWr;?Zl_T`PXgR zxmt@SsZeT98D3G(y+Ua}1Imh@QsK(F9UnWQiNcwTZBy|H&1YcQj%a8T5B+3RI1R=p z-2Zr6R->KhF@#I;IW`|ui{XC^-bG_(%Fq-KhLxT|^U|tG3YFQTs1*=zG)RghH459$l0CBa7C?< zn<9z+NDKwm%V_$7o>HNfIOGpgqY=@?P_@(xpo{HO&C`K%*iMe9;R~_F+=EBAp|-)^ z;{S>VXAFOJ|BAacNs7uzsr5G|~#3O3nygBk{Lw*IfP|XHSkrkg|(EzkX zU>6_obJbu*Yi~Kph*h~82j<-=WelM>(4_UHG{2SrnH+80he>~8vZ0wE)O|qrnvPzK zBEm|YT*kOVG~^_lg@$Xqt27SEM9Yv329=C6I(@W8&4_D>!2&JKYIPNlp;3nhw3pPW zbTqletva$)Wi_bv;S~UJt+qWisBR90Vi?e36dg>)Nkn&QshLu(tN{1K4y+P*lb8-f z=!}nW%#q$WDikKp49&vd)G*o~=#6hdB&E_RgK~rc9$__|_~2cMuhjZ3qKV?j_;iZ! zWxYn#2CYQ_BESGJnTl)UKcOs*!<62^51NY(`PHU|HCke~T9f=?F{Sq3Zvr*> zC`aY=?+W6=Ce$NN)tp7h5JM8<07`vr z)+3hE05XOY83T!4e?MX?eg2#mz})yYYng|pT@+!(VuCY!)se2$tq;=u55 z%09(1cvS46_iub|X`IbmeE6qMEKF;x{Fwv3N~f5L%C8T^bgP -#include -using namespace std; - -int main() { - int T, K, temp, i, j, no_solve, no_moreK, no_atmost; - float N; - int arr[1000]; - cin >> T; - - while(T--) { - cin >> N >> K; - no_solve = 0; - no_moreK = 0; - no_atmost = 0; - for(i = 0; i < N; i++) { - cin >> arr[i]; - } - // Here we decided the count of no pbs solved - for(i = 0; i < N; i++) { - if(arr[i] != -1) { - no_solve++; - } - } - - // Pbs taken time more than K; - - for(i = 0; i < N; i++) { - if(arr[i] > K) { - no_moreK++; - } - } - - - if(no_solve == N && no_moreK == 0) { - for(i = 0; i < N; i++) { - if(arr[i] <= 1) { - no_atmost++; - } - } - } - - - - temp = 0; - if(no_solve < ceil(N/2)) { - cout << "Rejected" << endl; - } - else if(no_moreK >= 1) { - cout << "Too Slow" << endl; - } - else if(no_atmost == N) { - cout << "Bot" << endl; - } - else { - cout << "Accepted" << endl; - } - - - - - - - - - } - return 0; - -} \ No newline at end of file diff --git a/C++/bear_ladder.cpp b/C++/bear_ladder.cpp deleted file mode 100644 index cc1c759..0000000 --- a/C++/bear_ladder.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -using namespace std; - -int main() { - long long int Q, a, b, i, nat_a, nat_b, diff; - cin >> Q; - while(Q--) { - cin >> a >> b; - nat_a = a % 2; - nat_b = b % 2; - // 0 -> Even, 1 -> Odd - //diff = abs(a - b); - if(nat_a == 1 && nat_b == 0) { - //diff = b - a; - diff = a - b; - if(diff == -1) { - cout << "YES" << endl; - } - else if(diff == 1) { - cout << "NO" << endl; - } - } - if(nat_a == 0 && nat_b == 0) { - //diff = b - a; - diff = abs(a - b); - - if(diff == 2) { - cout << "YES" << endl; - } - } - if(nat_a == 1 && nat_b == 1) { - //diff = b - a; - diff = abs(a - b); - - if(diff == 2) { - cout << "YES" << endl; - } - } - if((nat_a == 0 || nat_b == 0 || nat_a == 1 || nat_b == 1)) { - diff = abs(a - b); - - if(diff > 2) - cout << "NO" << endl; - } - if((a % 2 == 0) && (b = a + 1)) { - diff = abs(a - b); - - if(diff == 1) { - cout << "NO" << endl; - } - } - if(nat_a == 0 && nat_b == 1) { - diff = a - b; - if(diff == 1) { - cout << "YES" << endl; - } - } - - } - return 0; - - -} \ No newline at end of file diff --git a/C++/bin_mex.cpp b/C++/bin_mex.cpp deleted file mode 100644 index 21ed044..0000000 --- a/C++/bin_mex.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -using namespace std; - -int main() { - long long int i, j, temp, num, flag, T; - string str, binary, zero; - zero.push_back('0'); - cin >> T; - while(T--) { - cin >> str; - flag = 1; - num = 0; - while(flag) { - if(str.find(zero) == std::string::npos) { - cout << "0" << endl; - break; - } - binary = std::bitset<32>(num).to_string(); //to binary - int len = log2(num)+1; - //if(num != 0) - binary.erase(0,32-len); - //std::cout< -#include -#include -#include -int main() -{ - int T; - std:: cin >> T; - while(T--) { - int n; - std:: cin >> n; - for(auto i = 1; i <= n; ++i) { - std::string binary = std::bitset<32>(i).to_string(); //to binary - int len = log2(i)+1; - binary.erase(0,32-len); - std::cout< -using namespace std; - -void bubbleSort(int array[], int size) { - for (int step = 0; step < size; ++step) { - for (int i = 0; i < size - step; ++i) { - if (array[i] > array[i + 1]) { - int temp = array[i]; - array[i] = array[i + 1]; - array[i + 1] = temp; - } - } - } -} -void printArray(int array[], int size) { - for (int i = 0; i < size; ++i) { - cout << " " << array[i]; - } - cout << "\n"; -} -int main() { - int data[] = {-2, 45, 0, 11, -9}; - int size = sizeof(data) / sizeof(data[0]); - bubbleSort(data, size); - cout << "Sorted Array in Ascending Order:\n"; - printArray(data, size); -} \ No newline at end of file diff --git a/C++/buying_new_tables.cpp b/C++/buying_new_tables.cpp deleted file mode 100644 index 7c54333..0000000 --- a/C++/buying_new_tables.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -using namespace std; - -void solve_test() -{ - int number_options, budjet; - int width, heigth, price; - int max_width = 0, max_heiht = 0; - cin >> number_options >> budjet; - while (number_options--) - { - cin >> width >> heigth >> price; - if (price > budjet) - continue; - else - { - // The price is within the budjet - if ((max_heiht * max_width) < (heigth * width)) - { - max_width = width; - max_heiht = heigth; - } - } - } - - if (max_width == 0 && max_heiht == 0) - cout << "no tablet" << endl; - else - cout << max_heiht * max_width << endl; -} - -int main() { - int test_cases; - cin >> test_cases; - - while (test_cases--) - solve_test(); - return 0; -} diff --git a/C++/chef_and_bulb_invention.cpp b/C++/chef_and_bulb_invention.cpp deleted file mode 100644 index e39074d..0000000 --- a/C++/chef_and_bulb_invention.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include - -#define inputv(x, n) for(ll i = 0; i < n; i++) cin >> x[i]; -using namespace std; - -typedef long long int ll; - -int main() -{ - ll t; - cin >> t; - while(t--) - { - ll n, p, k; - cin >> n >> p >> k; - ll ans; - ll mod_p = p % k; - if(n % k <= mod_p - 1) - { - ans = (n % k)*(n/k + 1) + (mod_p - n%k) * (n/k); - ans = ans + (p/k + 1); - } - else - { - ans = (mod_p)*(n/k + 1); - ans = ans + (p/k + 1); - } - cout << ans << endl; - } - return 0; -} diff --git a/C++/chef_and_masks.cpp b/C++/chef_and_masks.cpp deleted file mode 100644 index d8d439d..0000000 --- a/C++/chef_and_masks.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -using namespace std; -int main() -{ - int n, i; - cin >> n; - int a[n], b[n]; - for (i = 0; i < n; i++) - { - cin >> a[i] >> b[i]; - } - for (i = 0; i < n; i++) - { - a[i] = a[i] * 100; - b[i] = b[i] * 10; - if (a[i] > b[i]) - { - cout << "Cloth" - << "\n"; - } - else if (a[i] < b[i]) - { - cout << "Disposable" - << "\n"; - } - else if (a[i] == b[i]) - { - cout << "Cloth" - << "\n"; - } - } - return 0; -} \ No newline at end of file diff --git a/C++/chef_and_round_run.cpp b/C++/chef_and_round_run.cpp deleted file mode 100644 index 1700666..0000000 --- a/C++/chef_and_round_run.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include -#define REP(i,n) for (int i = 1; i <= n; i++) -#define mod 1000000007 -#define pb push_back -#define ff first -#define ss second -#define ii pair -#define vi vector -#define vii vector -#define lli long long int -#define endl '\n' - -using namespace std; -vi ar[1000001]; -vi tr[1000001]; -vi scc , order; - -int vis[1000001]; -int val[1000001]; - -int dfs(int node) -{ - vis[node] = 1; - - for(int adj : ar[node]) - if(vis[adj] == 0) - dfs(adj); - - order.pb(node); -} - -int dfs1(int node) -{ - vis[node] = 1; - - for(int adj : tr[node]) - if(vis[adj] == 0) - dfs1(adj); - - scc.pb(node); -} - - -int main() -{ - int t , n , res; - cin>>t; - while(t--) - { - - //input and reset section - cin>>n; - order.clear() , res = 0; - REP(i , n) ar[i-1].clear() , tr[i-1].clear() , vis[i-1] = 0 , cin>>val[i-1]; - - - //graph construction section - REP(i , n) - { - int a = i - 1; - int b = (i - 1 + val[i-1] + 1) % n; - - ar[a].pb(b); - tr[b].pb(a); - } - - //SCC section - REP(i , n) - if(vis[i-1] == 0) - dfs(i-1); - - REP(i , n) vis[i-1] = 0; - - reverse(order.begin() , order.end()); - for(int i : order) - if(vis[i] == 0) - { - scc.clear(); - dfs1(i); - - if(scc.size() == 1 && (scc[0] != ar[scc[0]][0])) continue; - - res += scc.size(); - } - - cout< -using namespace std; -long long int facto=1; -long long int pow(long long a, long long b, long long mod) { - long long x = 1, y = a; - while(b > 0) { - if(b%2 == 1) { - x=(x*y); - if(x>mod) x%=mod; - } - y = (y*y); - if(y>mod) y%=mod; - b /= 2; - } - return x; -} - - - -// Returns n^(-1) mod p - long long modInverse( long long n, long long int p) -{ - return pow(n, p - 2, p); -} - -// Returns nCr % p using Fermat's little -// theorem. - long long nCrModPFermat( long long n, - long long int r, long long int p) -{ - // Base case - if (r == 0) - return 1; - - // Fill factorial array so that we - // can find all factorial of r, n - // and n-r - long long fac[n + 1]; - fac[0] = 1; - for (int i = 1; i <= n; i++) - fac[i] = (fac[i - 1] * i) % p; - - return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; -} - -long long int fact(int x) -{ - if(x==1) - return facto; - facto*=x; - return fact(x-1); -} -int main() -{ - long long int i,j,n,m,arr[1000000],t,maxm=0,val,mod=1e9+7,val1,val2,temp,x,y,val3; - cin>>t; - for(j=0;j>n; - maxm=0; - val=0; - for(i=0;i>arr[i]; - } - if(n==1) - cout<<2<<"\n"; - else - { - for(i=0;i -using namespace std; -#define mod 1000000007 -int main(){ - int t; - cin>>t; - while(t--){ -int i,j,n,k,c; -cin>>n>>k; -vector v(n); -for(i=0;i>v[i]; -map mp; -int cost[n][n],ans[n]; -for(i=0;i2 )c=1; - else c=0; - cost[i][j]=cost[i][j-1]+c; - } - -} -mp.clear(); -} -ans[0]=k; -for(i=1;i -#include -using namespace std; - -int main() { - long long int i, j, temp, T, group_ct, N, count_1,flag; - string str; - char ch; - string :: iterator itr; - cin >> N; - while(N--) { - cin >> str; - group_ct = 0; - count_1 = 0; - flag = 0; - // Handling all Zeros case; - itr = find(str.begin(), str.end(), '1'); - if(itr == str.end()) { - // Means no any 1 present all are zeros. - cout << "0" << endl; - flag = 1; - } - if(flag == 0) { - itr = find(str.begin(), str.end(), '0'); - if(itr == str.end()) { - cout << "1" << endl; - flag = 2; - } - } - // Now handling combination case; - if(flag == 0) { - // check '01' pair now. - for(i = 0; i < str.size()-1; i++) { - if(str[i] == '1' && str[i+1] == '0') { - group_ct++; - count_1 = 0; - } - else if(str[i] == '1' && str[i+1] == '1') { - count_1++; - } - - } - - if(count_1 > 0 || str[i] == '1') { - group_ct++; - } - - - cout << group_ct << endl; - - } - str.clear(); - - - } - return 0; -} \ No newline at end of file diff --git a/C++/chef_rotine.cpp b/C++/chef_rotine.cpp deleted file mode 100644 index d70ac33..0000000 --- a/C++/chef_rotine.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -using namespace std; - -int main() { - long long T, len, count = 0, i; - char str[100000]; - cin >> T; - while(T--) { - cin >> str; - len = strlen(str); - count = 0; - for(i = 0; i < len; i++) { - if(str[i] == 'C') { - if(str[i + 1] == 'C' || str[i + 1] == 'E' || str[i + 1] == 'S') { - count++; - } - } - else if(str[i] == 'E') { - if(str[i + 1] == 'E' || str[i + 1] == 'S') { - count++; - - } - } - else if(str[i] == 'S') { - if(str[i + 1] == 'S') { - count++; - } - } - } - if(count == (len - 1)) { - cout << "yes" << endl; - } - else { - cout << "no" << endl; - } - - } - return 0; -} \ No newline at end of file diff --git a/C++/coder_life.cpp b/C++/coder_life.cpp deleted file mode 100644 index 89ec916..0000000 --- a/C++/coder_life.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -using namespace std; - -int main() { - int T; - char str[1000], i, flag_bored = 0, count_1, j, flag; - cin >> T; - while(T--) { - cin >> str; - count_1 = 0; - for(i = 0; i < 30; i++) { - for(j = i + 1; j < 30; j++) { - if(str[i] == '1' && str[j] == '1') { - count_1++; - if(count_1 >= 5) { - flag = 1; - cout << "#coderlifematters" << endl; - - break; - } - else if(count_1 < 5) { - flag = 0; - } - } - else if(str[i] == '0' || str[j] == '0') { - count_1 = 0; - flag = 0; - } - } - - - } - if(flag == 0) { - cout << "#allcodersarefun" << endl; - break; - } - } - return 0; - -} \ No newline at end of file diff --git a/C++/countwords.cpp b/C++/countwords.cpp deleted file mode 100644 index bd161f5..0000000 --- a/C++/countwords.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -using namespace std; - -int main() { - int t; - cin>>t; - while(t--) - { - int N,M; - cin>>N>>M; - cout< -#include -using namespace std; - - - - - void Cyclic_sort(int arr[],int n) { - - int i=1; - - while(i -#include -#include -using namespace std; -int main() -{ - //getting local time - time_t t = time(NULL); - tm *timePtr = localtime(&t); - //store local time in variables - int sec = (timePtr->tm_sec); - int min = (timePtr->tm_min); - int hours = (timePtr->tm_hour); - string timestr; - //convert time to 12 hrs format - if (hours > 12) - { - hours = hours % 12; - timestr = "PM"; - } - else - { - timestr = "AM"; - } - while (true) - { - system("cls"); - //printing time - cout << "\n\nClock Local time\n"; - cout << "*******************************\n\n"; - cout << " |" << hours << " : " << min << " : " << sec << " " << timestr << " |" << endl; - cout << "*******************************\n\n"; - //increment sec min and hours - sec++; - if (sec > 59) - { - sec = 0; - min++; - } - if (min > 59) - { - min = 0; - hours++; - } - if (hours > 12) - { - hours = 1; - } - Sleep(1000); - } - return 0; -} - diff --git a/C++/div.cpp b/C++/div.cpp deleted file mode 100644 index 82b0a90..0000000 --- a/C++/div.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -using namespace std; - -int main() { - long long int T, N, K, i, j, temp, count_ans, flag; - cin >> T; - while(T--) { - cin >> N >> K; - long long int arr[N]; - for(i = 0; i < N; i++) { - cin >> arr[i]; - } - count_ans = 0; - - // Now array has been taken; - for(i = 0; i < N; i++) { - - if(arr[i] % K != 0) { - j = K; - temp = arr[i]; - flag = 0; - for(i = 0; i < j; i++) { - temp = temp + temp; - - } - if(temp % K != 0) { - cout << "NO" << endl; - flag = 1; - break; - } - } - } - if(flag == 0) - cout << "YES" << endl; - } - return 0; - -} \ No newline at end of file diff --git a/C++/divisor.cpp b/C++/divisor.cpp deleted file mode 100644 index 325a73f..0000000 --- a/C++/divisor.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -using namespace std; - -int main() { - long long int N, i, temp; - cin >> N; - // finding divisors. - - for(i = 1; i <= 10; i++) { - if(N%i == 0) { - temp = i; - } - } - cout << temp << endl; - return 0; - -} \ No newline at end of file diff --git a/C++/eqdiffer.cpp b/C++/eqdiffer.cpp deleted file mode 100644 index a8d13da..0000000 --- a/C++/eqdiffer.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -using namespace std; -typedef long long int ll; -typedef pair pi; -typedef vector vi; -#define mod 1000000007 - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t; - cin >> t; - - while(t--){ - int n; - cin >> n; - mapm; - for(int i=0;i> x; - m[x]+=1; - } - if(n<=2) { - cout << 0 << "\n"; - continue; - } - int max_freq=INT_MIN; - for(auto it=m.begin();it!=m.end();it++){ - max_freq=max(it->second,max_freq); - } - - if(max_freq==1) cout << n-2 << endl; - else cout << (n-max_freq) << endl; - } - - return 0; -} \ No newline at end of file diff --git a/C++/even_diff.cpp b/C++/even_diff.cpp deleted file mode 100644 index c4ecad7..0000000 --- a/C++/even_diff.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -using namespace std; - -int main() { - long int T, N, count; - cin >> T; - while(T--) { - cin >> N; - long int arr[N]; - count = 0; - for(int i = 0; i < N; i++) { - cin >> arr[i]; - } - // Now array has been taken. - for(int i = 0; i < N; i++) { - if(arr[i] % 2 == 1) { - count++; - } - } - cout << count << endl; - - } - return 0; - -} \ No newline at end of file diff --git a/C++/evenorodd.cpp b/C++/evenorodd.cpp deleted file mode 100644 index 1712004..0000000 --- a/C++/evenorodd.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -using namespace std; - - -void solve(){ - - int n; - - int e= 0; - int o= 0; - - if(n%2 == 0){ - e = n/2; - o = n/2; - }else{ - e = n/2; - o= (n+1)/2; - } - if(n<=1){ - cout<<"0"<>tc; - - while(tc--){ - solve(); - } - - return 0; -} diff --git a/C++/find_LCA_binary_tree.cpp b/C++/find_LCA_binary_tree.cpp deleted file mode 100644 index 5d69516..0000000 --- a/C++/find_LCA_binary_tree.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Lowest Common Ancestor of a Binary Tree -/** -Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. - */ - -class Solution { - public: - TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { - if (!root || root == p || root == q) - return root; - - TreeNode* l = lowestCommonAncestor(root->left, p, q); - TreeNode* r = lowestCommonAncestor(root->right, p, q); - - if (l && r) - return root; - return l ? l : r; - } -}; diff --git a/C++/find_diameter_binary_trees.cpp b/C++/find_diameter_binary_trees.cpp deleted file mode 100644 index 7485d04..0000000 --- a/C++/find_diameter_binary_trees.cpp +++ /dev/null @@ -1,57 +0,0 @@ - -// C++ program to find the diameter of a Binary Tree -#include -using namespace std; - -struct node { - int data; - struct node *left, *right; -}; - -struct node* newNode(int data); - -int diameterOpt(struct node* root, int* height) -{ - int lh = 0, rh = 0; - - int ldiameter = 0, rdiameter = 0; - - if (root == NULL) { - *height = 0; - return 0; - } - - ldiameter = diameterOpt(root->left, &lh); - rdiameter = diameterOpt(root->right, &rh); - - *height = max(lh, rh) + 1; - - return max(lh + rh + 1, max(ldiameter, rdiameter)); -} - -struct node* newNode(int data) -{ - struct node* node - = (struct node*)malloc(sizeof(struct node)); - node->data = data; - node->left = NULL; - node->right = NULL; - - return (node); -} - -// Test Code -int main() -{ - - struct node* root = newNode(1); - root->left = newNode(2); - root->right = newNode(3); - root->left->left = newNode(4); - root->left->right = newNode(5); - - int height = 0; - cout << "Diameter of the given binary tree is " << diameterOpt(root, &height); - - return 0; -} diff --git a/C++/football.cpp b/C++/football.cpp deleted file mode 100644 index 0212267..0000000 --- a/C++/football.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -using namespace std; - -int main() { - int T, i, arr_A[100], arr_B[100], score[100], max, N; - cin >> T; - while(T--) { - cin >> N; - max = INT_MIN; - for(i = 0; i < N; i++) { - cin >> arr_A[i]; - } - for(i = 0; i < N; i++) { - cin >> arr_B[i]; - } - // calculation of score - for(i = 0; i < N; i++) { - score[i] = (arr_A[i] * 20) - (arr_B[i] * 10); - } - for(i = 0; i < N; i++) { - if(score[i] > max) { - max = score[i]; - } - } - if(max < 0) - cout << "0" << endl; - else if(max > 0) - cout << max << endl; - - } - return 0; - -} \ No newline at end of file diff --git a/C++/gany_house.cpp b/C++/gany_house.cpp deleted file mode 100644 index ce6e264..0000000 --- a/C++/gany_house.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -using namespace std; - -// Function for returning no. of digits; - -int no_digit(int temp) { - int flag = 0; - while(temp > 0) { - flag++; - temp = temp / 10; - } - return flag; -} - - -// Rec. function for generating fibonacci sequence. - - -// z gives next fibonacii number; - -int main() { - int val, i, x = 0, y = 1, z = 0, count = 1, res; - cin >> val; - for(i = 0; i < 1000; i++) { - z = x + y; - count++; - if(no_digit(z) == val) { - res = count; - break; - } - x = y; - y = z; - } - cout << res << endl; - -} \ No newline at end of file diff --git a/C++/gcpd.cpp b/C++/gcpd.cpp deleted file mode 100644 index 0c996c5..0000000 --- a/C++/gcpd.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -using namespace std; - -int is_prime(int num) { - int i, prime = 1; - if(num == 1) { - return 0; - } - else if(num == 2) { - return 1; - } - for(i = 3; i <= num/ 2; i++) { - if(num % i == 0) { - prime = 0; - break; - - } - } - if(prime == 0) { - return 0; - } - else if(prime == 1) { - return 1; - } - -} - -int main() { - - int a, b, is_gcpd = 0, temp, res, flag, i, small; - cin >> a >> b; - if(a < b) { - small = a; - } - else { - small = b; - } - for(i = small; i > 0; i--) { - if(a % i == 0 && b % i == 0 && is_prime(i) == 1) { - res = i; - is_gcpd = 1; - break; - } - } - if(is_gcpd == 1) { - cout << res << endl; - - } - else if(is_gcpd == 0) { - cout << "-1" << endl; - } - - return 0; - - -} \ No newline at end of file diff --git a/C++/gift.cpp b/C++/gift.cpp deleted file mode 100644 index 24d7ef7..0000000 --- a/C++/gift.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -using namespace std; - -long long int Divisor(long long int n) -{ - int cnt = 0; - for (int i = 1; i <= sqrt(n); i++) { - if (n % i == 0) { - // If divisors are equal, - // count only one - if (n / i == i) - cnt++; - - else // Otherwise count both - cnt = cnt + 2; - } - } - return cnt; -} - - -int main() { - long long int L, R, i, j, flag = 0, T, N, div1, div2; - cin >> T; - while(T--) { - cin >> N; - long long int arr[N]; - for(i = 0; i < N; i++) { - cin >> arr[i]; - } - flag = 0; - for(L = 0, R = N-1; L <= R; L++, R--) { - div1 = Divisor(arr[L]); - div2 = Divisor(arr[R]); - - if(div1 % 2 == 1 && div2 % 2 == 1) { - cout << R-L << endl; - flag = 1; - } - - } - if(L > R && flag == 0) { - cout << "0" << endl; - } - - - } - return 0; - -} \ No newline at end of file diff --git a/C++/greaterAverage.cpp b/C++/greaterAverage.cpp deleted file mode 100644 index e9c7405..0000000 --- a/C++/greaterAverage.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -using namespace std; - -int main() -{ - int T, A, B, C; - cin >> T; - - while (T--) - { - cin >> A >> B >> C; - - float average = (A + B) / 2.0; - - if (average > C) - { - cout << "YES" << endl; - } - else - { - cout << "NO" << endl; - } - } - - return 0; -} \ No newline at end of file diff --git a/C++/inter_xor.cpp b/C++/inter_xor.cpp deleted file mode 100644 index 3a17605..0000000 --- a/C++/inter_xor.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include -using namespace std; - -vector decToBinary(int n) -{ - // array to store binary number - long long int temp; - vector arr; - // counter for binary array - int i = 0; - while (n > 0) { - - // storing remainder in binary array - temp = n % 2; - arr.push_back(temp); - n = n / 2; - i++; - } - - // printing binary array in reverse order - reverse(arr.begin(), arr.end()); - return arr; -} - -long long int binaryToDecimal(long long int n) -{ - long long int num = n; - long long int dec_value = 0; - - // Initializing base value to 1, i.e 2^0 - long long int base = 1; - - long long int temp = num; - while (temp) { - long long int last_digit = temp % 10; - temp = temp / 10; - - dec_value += last_digit * base; - - base = base * 2; - } - - return dec_value; -} - -int main() { - long long int A = 0, B = 0, C, i, j, T, temp; - vector Crr; - vector Arr; - vector Brr; - cin >> T; - while(T--) { - cin >> C; - A = 0; - B = 0; - // Now converting C into Crr. - Crr = decToBinary(C); - Arr.push_back(1); - Brr.push_back(0); - for(i = 1; i < Crr.size(); i++) { - if(Crr[i] == 1) { - if(Arr[i-1] == 0) { - Arr.push_back(1); - Brr.push_back(0); - } - else if(Arr[i-1] == 1) { - Arr.push_back(0); - Brr.push_back(1); - } - } - else if(Crr[i] == 0) { - Arr.push_back(1); - Brr.push_back(1); - } - } - // Now converting binary into decimal. - for (auto &d : Arr) - { - A = A * 10 + d; - } - - for(auto &d: Brr) { - B = B * 10 + d; - } - A = binaryToDecimal(A); - B = binaryToDecimal(B); - cout << A*B << endl; - Arr.clear(); - Brr.clear(); - Crr.clear(); - } - return 0; - -} \ No newline at end of file diff --git a/C++/intersection-of-two-linked-lists.cpp b/C++/intersection-of-two-linked-lists.cpp deleted file mode 100644 index 5252b66..0000000 --- a/C++/intersection-of-two-linked-lists.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. -// If the two linked lists have no intersection at all, return null. - -// Time: O(m + n) -// Space: O(1) - -/** - * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode(int x) : val(x), next(NULL) {} - * }; - */ - -class Solution { -public: - ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { - ListNode *curA = headA, *curB = headB; - while (curA != curB) { - curA = curA ? curA->next : headB; - curB = curB ? curB->next : headA; - } - return curA; - } -}; diff --git a/C++/matrix.cpp b/C++/matrix.cpp deleted file mode 100644 index 2d12ba6..0000000 --- a/C++/matrix.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -using namespace std; - -int main() { - int M, N, a, b, i, j, k, temp, flag, sum_row = 0, sum_col = 0, arr[100][100], res; - cin >> M >> N; - //cin >> a >> b; - for(i = 0; i < M; ++i) { - for(j = 0; j < N; ++j) { - cin >> arr[i][j]; - } - } - - // matrix is taken - // sum of row - - for(i = 0; i < M; i++) { - for(j = 0; j < N; j++) { - cout << arr[i][j]; - } - cout << endl; - } - - cin >> a >> b; - temp = a; - flag = b; - - // Finding sum of row - for(i = 0; i < N; i++) { - temp = a; - sum_row = sum_row + arr[temp][i]; - } - - // sum of col - - for(i = 0; i < M; i++) { - flag = b; - sum_row = sum_row + arr[i][flag]; - } - - - - res = sum_row + sum_col; - res = res - arr[a][b]; - - cout << res << endl; - return 0; - - -} \ No newline at end of file diff --git a/C++/maxima.cpp b/C++/maxima.cpp deleted file mode 100644 index 3503f01..0000000 --- a/C++/maxima.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -using namespace std; - -int main() { - long long int i , F_max, S_max, minm, N, temp, result, T; - vector arr; - cin >> T; - while(T--) { - cin >> N; - result = 0; - F_max = INT_MIN; - S_max = INT_MIN; - minm = 0; - for(i = 0; i < N; i++) { - cin >> temp; - arr.push_back(temp); - } - // Now let's find First Max, 2nd max and min element. - F_max = *max_element(arr.begin(), arr.end()); - minm = *min_element(arr.begin(), arr.end()); - for(i = 0; i < N; i++) { - if(arr[i] != F_max) { - S_max = max(S_max, arr[i]); - } - - } - if(S_max == INT_MIN) { - S_max = F_max; - } - - - // Now we got all. - result = (abs(F_max-minm) + abs(minm-S_max) + abs(S_max-F_max)); - cout << result << endl; - arr.clear(); - - } - - return 0; - -} - diff --git a/C++/maximise_islands.cpp b/C++/maximise_islands.cpp deleted file mode 100644 index 368d85d..0000000 --- a/C++/maximise_islands.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include -using namespace std; -int main() -{ - int t,n,m; - cin>>t; - while(t--) - { - cin>>n>>m; - char str[1001][1001]; - for(int i=0;i>str[i][j]; - int ctr=0,ctr1=0; - if((n*m)%2==0) - { - for(int i=0;i - -using namespace std; - -void solve_test() - -{ - - int n, k, current; - - cin >> n >> k; - - int arr[n]; - - int i; - - for (i = 0; i < n; i++) cin >> arr[i]; - - int result = 0; - - for (i = 0; i < n; i++) - - { - - current = arr[i] + k; - - if (current % 7 == 0) - - result++; - - } - - cout << result << endl; - -} - -int main() { - - int t; - - cin >> t; - - while (t--) - - solve_test(); - - return 0; - -} diff --git a/C++/ors_of_ands.cpp b/C++/ors_of_ands.cpp deleted file mode 100644 index ec0dbfa..0000000 --- a/C++/ors_of_ands.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -using namespace std; -int main() -{ - long long int i,j,n,m,t,q,arr[1000000],fre[32],pos,val,x,y,a,ans=0; - cin>>t; - while(t--) - { - cin>>n>>q; - memset(fre,0,sizeof(fre)); - for(i=0;i>arr[i]; - ans=0; - // a=arr[0]; - for(i=0;i>pos>>val; - x=arr[pos-1]; - ans=0; - for(i=0;i<32;i++) - { - if(x&(1< -#include -using namespace std; - - -int sum(int arr[], int from, int to) -{ - int total = 0; - for (int i = from; i <= to; i++) - total += arr[i]; - return total; -} - -int findMax(int arr[], int n, int k) -{ - int dp[k + 1][n + 1] = { 0 }; - - for (int i = 1; i <= n; i++) - dp[1][i] = sum(arr, 0, i - 1); - - for (int i = 1; i <= k; i++) - dp[i][1] = arr[0]; - - for (int i = 2; i <= k; i++) { - for (int j = 2; j <= n; j++) { - - int best = INT_MAX; - - for (int p = 1; p <= j; p++) - best = min(best, max(dp[i - 1][p], - sum(arr, p, j - 1))); - - dp[i][j] = best; - } - } - - return dp[k][n]; -} - -// driver function -int main() -{ - int arr[] = { 10, 20, 60, 50, 30, 40 }; - int n = sizeof(arr) / sizeof(arr[0]); - int k = 3; - cout << findMax(arr, n, k) << endl; - return 0; -} diff --git a/C++/palindrome_linked_list.cpp b/C++/palindrome_linked_list.cpp deleted file mode 100644 index 18d3ab8..0000000 --- a/C++/palindrome_linked_list.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Palindrome Linked List - -/* -Given the head of a singly linked list, return true if it is a palindrome. -Input: head = [1,2,2,1] -Output: true -*/ - -/** - * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode() : val(0), next(nullptr) {} - * ListNode(int x) : val(x), next(nullptr) {} - * ListNode(int x, ListNode *next) : val(x), next(next) {} - * }; - -class Solution { - public: - bool isPalindrome(ListNode* head) { - ListNode* slow = head; - ListNode* fast = head; - - while (fast && fast->next) { - slow = slow->next; - fast = fast->next->next; - } - - if (fast) - slow = slow->next; - slow = reverseList(slow); - - while (slow) { - if (slow->val != head->val) - return false; - slow = slow->next; - head = head->next; - } - - return true; - } - - private: - ListNode* reverseList(ListNode* head) { - ListNode* prev = nullptr; - - while (head) { - ListNode* next = head->next; - head->next = prev; - prev = head; - head = next; - } - - return prev; - } -}; diff --git a/C++/pathetic_sums.cpp b/C++/pathetic_sums.cpp deleted file mode 100644 index b0ed7fa..0000000 --- a/C++/pathetic_sums.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -using namespace std; -long long dist[1000000]; -vector adj[1000000]; -void dfs(int u,int v) -{ - dist[u]=dist[v]^1; - for(int child:adj[u]) - { - if(child!=v) - dfs(child,u); - } -} -int main() -{ - long long i,j,n,m,u,v,t; - cin>>t; - while(t--) - { - memset(dist,0,sizeof(dist)); - for(i=0;i<=10000;i++) - adj[i].clear(); - cin>>n; - for(i=0;i>u>>v; - adj[u].push_back(v); - adj[v].push_back(u); - } - dfs(1,0); - for(i=1;i<=n;i++) - cout< -#include - -using namespace std; - -int main() { - - int T; - float x1, x2, x3, v1, v2, d1, d2, t1, t2; - cin >> T; - while(T--) { - cin >> x1 >> x2 >> x3 >> v1 >> v2; - d1 = x3 - x1; - d2 = x2 - x3; - t1 = d1 / v1; - t2 = d2 / v2; - if(t1 < t2) { - cout << "" - } - } - return 0; -} diff --git a/C++/reverseLinkedList.cpp b/C++/reverseLinkedList.cpp deleted file mode 100644 index 1d97dff..0000000 --- a/C++/reverseLinkedList.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - Given the head of a singly linked list, reverse list & return - Ex. head = [1,2,3,4,5] -> [5,4,3,2,1], head = [1,2] -> [2,1] - - Maintain prev, curr, & next pointers, iterate thru & reverse - - Time: O(n) - Space: O(1) -*/ - -/** - * Definition for singly-linked list. - * struct ListNode { - * int val; - * ListNode *next; - * ListNode() : val(0), next(nullptr) {} - * ListNode(int x) : val(x), next(nullptr) {} - * ListNode(int x, ListNode *next) : val(x), next(next) {} - * }; - */ -class Solution { -public: - ListNode* reverseList(ListNode* head) { - if (head == NULL || head->next == NULL) { - return head; - } - - ListNode* prev = NULL; - ListNode* curr = head; - ListNode* next = curr->next; - - while (curr != NULL) { - next = curr->next; - curr->next = prev; - prev = curr; - curr = next; - } - - return prev; - } -}; diff --git a/C++/sieve_of_eratosthenes.cpp b/C++/sieve_of_eratosthenes.cpp deleted file mode 100644 index 51afdba..0000000 --- a/C++/sieve_of_eratosthenes.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// C++ program to print all primes -// smaller than or equal to -// n using Sieve of Eratosthenes -#include -using namespace std; - -void SieveOfEratosthenes(int n) -{ - - bool prime[n + 1]; - memset(prime, true, sizeof(prime)); - - for (int p = 2; p * p <= n; p++) - { - // If prime[p] is not changed, - // then it is a prime - if (prime[p] == true) - { - for (int i = p * p; i <= n; i += p) - prime[i] = false; - } - } - - for (int p = 2; p <= n; p++) - if (prime[p]) - cout << p << " "; -} diff --git a/C++/slowSolution.cpp b/C++/slowSolution.cpp deleted file mode 100644 index b507d60..0000000 --- a/C++/slowSolution.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while(t--) - { - int maxt,maxn,maxs,x,p=0; - cin>>maxt>>maxn>>maxs; - - while(maxt--&&maxs>0) - { - if(maxs>=maxn) - { - maxs-=maxn; - p+=pow(maxn,2); - - } - else - { - p+=pow(maxs,2); - break; - } - - } - cout< -using namespace std; - -int main() { - int k, n, w; - cin >> k >> n >> w; - - int total_cost = 0; - for (int i = 1; i <= w; ++i) - { - total_cost += i * k; - } - if (total_cost <= n) - { - cout << 0 << endl; - } - else - cout << (total_cost - n ) << endl; - - - -} diff --git a/C++/sumofarray.cpp b/C++/sumofarray.cpp deleted file mode 100644 index b846f26..0000000 --- a/C++/sumofarray.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#define ll long long -#define pb push_back -#define fr(a, b) for (int i = a; i < b; i++) -#define rep(i, a, b) for (int i = a; i < b; i++) -#define mod 1000000007 -#define inf (1LL << 60) -#define all(x) (x).begin(), (x).end() -#define prDouble(x) cout << fixed << setprecision(10) << x -#define triplet pair> -#define goog(tno) cout << "Case #" << tno << ": " -#define fast_io \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) -#define read(x) \ - int x; \ - cin >> x -using namespace std; - -void init_code() -{ - fast_io; -#ifndef ONLINE_JUDGE - freopen("input.txt", "r", stdin); - freopen("output.txt", "w", stdout); -#endif -} - -int sum(int n, int a[]) -{ - if (n < 0) - return 0; - return sum(n - 1, a) + a[n]; -} - -int main() -{ - int n; - cin >> n; - int a[n]; - fr(0, n) cin >> a[i]; - - cout << sum(n - 1, a); - return 0; -} diff --git a/C++/that-is-my-score.cpp b/C++/that-is-my-score.cpp deleted file mode 100644 index 22d8a36..0000000 --- a/C++/that-is-my-score.cpp +++ /dev/null @@ -1,84 +0,0 @@ - -// https://www.codechef.com/problems/WATSCORE - -#include - -#include - -using namespace std; - -int solve_test() - -{ - - int my_score = 0; - - // Create a vector of 8 element and set all of them to 0 - - vectorscorable_marks(8, 0); - - int submission_id, submission_score; - - int number_submission; - - cin >> number_submission; - - - - for(int i =0; i < number_submission; i++) - - { - - cin >> submission_id >> submission_score; - - if(submission_id > 8 && submission_id < 1) - - continue; - - else - - { - - // There is a scorable submission_ - - if(scorable_marks[submission_id-1] < submission_score) - - scorable_marks[submission_id-1] = submission_score; - - } - - } - - - - for(int i=0; i < scorable_marks.size(); i++) - - my_score += scorable_marks[i]; - - - - return my_score; - -} - -int main() { - - - - int test_cases; - - cin >> test_cases; - - - - while(test_cases--) - - cout << solve_test() < -using namespace std; - -int main() { - int t,n,r,num,temp; -cin>>t; -while(t--)//Running a loop for the length of the given number -{ - cin>>n; - temp=n; - num=0; - while(n!=0) - { - r=n%10; - num=num*10+r; - n=n/10; - } - if(num==temp)//if the initial number and final calculated number is equal then wins else loses - cout<<"wins"< -#include -using namespace std; - -int main() { - long long int T, N, pi[10000], prob[10000], si[10000], sc[10000], count = 0,score = 0, i, j, k = 0, flag, m; - cin >> T; - while(T--) { - cin >> N; - count = 0; - score = 0; - for(i = 0; i < N; i++) { - cin >> pi[i]; - cin >> si[i]; - } - // Now pi[] contains N problems - // And si[] contains N scores - for(i = 0; i < N; i++) { - for(j = i + 1; j < N + 1; j++) { - if(pi[i] == pi[j]) { - if(si[i] > si[j]) { - count = si[i]; - } - else if(si[i] < si[j]) { - count = si[j]; - } - flag = count; - } - - } - if(pi[i] > 0 && pi[i] < 9) { - score = score + flag; - } - - } - cout << score << endl; - - } - return 0; -} diff --git a/C++/tictac.cpp b/C++/tictac.cpp deleted file mode 100644 index daaf16d..0000000 --- a/C++/tictac.cpp +++ /dev/null @@ -1,137 +0,0 @@ -#include -using namespace std; - -char square[10] = {'o','1','2','3','4','5','6','7','8','9'}; - -int checkwin(); -void board(); - -int main() -{ - int player = 1,i,choice; - - char mark; - do - { - board(); - player=(player%2)?1:2; - - cout << "Player " << player << ", enter a number: "; - cin >> choice; - - mark=(player == 1) ? 'X' : 'O'; - - if (choice == 1 && square[1] == '1') - - square[1] = mark; - else if (choice == 2 && square[2] == '2') - - square[2] = mark; - else if (choice == 3 && square[3] == '3') - - square[3] = mark; - else if (choice == 4 && square[4] == '4') - - square[4] = mark; - else if (choice == 5 && square[5] == '5') - - square[5] = mark; - else if (choice == 6 && square[6] == '6') - - square[6] = mark; - else if (choice == 7 && square[7] == '7') - - square[7] = mark; - else if (choice == 8 && square[8] == '8') - - square[8] = mark; - else if (choice == 9 && square[9] == '9') - - square[9] = mark; - else - { - cout<<"Invalid move "; - - player--; - cin.ignore(); - cin.get(); - } - i=checkwin(); - - player++; - }while(i==-1); - board(); - if(i==1) - - cout<<"==>\aPlayer "<<--player<<" win "; - else - cout<<"==>\aGame draw"; - - cin.ignore(); - cin.get(); - return 0; -} - - -int checkwin() -{ - if (square[1] == square[2] && square[2] == square[3]) - - return 1; - else if (square[4] == square[5] && square[5] == square[6]) - - return 1; - else if (square[7] == square[8] && square[8] == square[9]) - - return 1; - else if (square[1] == square[4] && square[4] == square[7]) - - return 1; - else if (square[2] == square[5] && square[5] == square[8]) - - return 1; - else if (square[3] == square[6] && square[6] == square[9]) - - return 1; - else if (square[1] == square[5] && square[5] == square[9]) - - return 1; - else if (square[3] == square[5] && square[5] == square[7]) - - return 1; - else if (square[1] != '1' && square[2] != '2' && square[3] != '3' - && square[4] != '4' && square[5] != '5' && square[6] != '6' - && square[7] != '7' && square[8] != '8' && square[9] != '9') - - return 0; - else - return -1; -} - - - - - -void board() -{ - system("cls"); - cout << "\n\n\tTic Tac Toe\n\n"; - - cout << "Player 1 (X) - Player 2 (O)" << endl << endl; - cout << endl; - - cout << " | | " << endl; - cout << " " << square[1] << " | " << square[2] << " | " << square[3] << endl; - - cout << "_____|_____|_____" << endl; - cout << " | | " << endl; - - cout << " " << square[4] << " | " << square[5] << " | " << square[6] << endl; - - cout << "_____|_____|_____" << endl; - cout << " | | " << endl; - - cout << " " << square[7] << " | " << square[8] << " | " << square[9] << endl; - - cout << " | | " << endl << endl; -} \ No newline at end of file diff --git a/C++/totalPrizeMoney.cpp b/C++/totalPrizeMoney.cpp deleted file mode 100644 index 637fea3..0000000 --- a/C++/totalPrizeMoney.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while (t--){ - int x,y; - cin>>x>>y; - cout<< (10*x)+(90*y)<< endl; - } - return 0; -} diff --git a/C++/whats_name.cpp b/C++/whats_name.cpp deleted file mode 100644 index e0cb4f7..0000000 --- a/C++/whats_name.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include -#include -#include -#include - -using namespace std; - -int main() { - int T, N; - - cin >> T; - N = T + 1; - cin.ignore(); - while(N--) { - string str, res; - getline(cin, str); - int i = 0, j = 1, m = 0, count = 0, space_count = 0, k; - for(i = 0; str[i] != '\0'; i++) { - if(str[i] == ' ') { - space_count++; - } - } - // Here we are having count of spaces. - // 3 Test Cases - //cout << space_count << " Space" << endl; - if(space_count == 0) { - if(str[0] > 64 && str[0] < 91) { - res[0] = str[0]; - } - else if(str[0] > 96 && str[0] < 123) { - res[0] = str[0] - 32; - } - for(i = 1; str[i] != '\0'; i++) { - if(str[i] > 96 && str[i] < 123) { - res[j] = str[i]; - j++; - count++; - } - else if(str[i] > 64 && str[i] < 91) { - res[j] = str[i] + 32; - j++; - count++; - } - } - } - //cout << "hare" << endl; - - for(i = 0; i <= count; i++) { - cout << res[i]; - } - cout << endl; - } - return 0; - -} \ No newline at end of file diff --git a/CNTRIBUTING.MD b/CNTRIBUTING.MD deleted file mode 100644 index 4ff7ee3..0000000 --- a/CNTRIBUTING.MD +++ /dev/null @@ -1,43 +0,0 @@ ---- - -# Steps For Contribution - -0. Star - -1. Fork - -2. Clone the forked repository. -```css -git clone https://github.com//Hacktoberfest-2022 -``` - -3. Navigate to the project directory. -```py -cd Hacktoberfest-2022 -``` - -4. Create a new branch. -```css -git checkout -b -``` - -5. Make changes. - -6. Stage your changes and commit -```css -git add -A - -git commit -m "" -``` - -7. Push your local commits to the remote repo. -```css -git push -u origin -``` - -8. Create a Pull Request. - -9. Congratulations! 🎉 you've made your contribution. - - ---- diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 41dd9eb..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,127 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -We as members, contributors, and leaders pledge to make participation in our -community a harassment-free experience for everyone, regardless of age, body -size, visible or invisible disability, ethnicity, sex characteristics, gender -identity and expression, level of experience, education, socio-economic status, -nationality, personal appearance, race, religion, or sexual identity -and orientation. - -We pledge to act and interact in ways that contribute to an open, welcoming, -diverse, inclusive, and healthy community. - -## Our Standards - -Examples of behavior that contributes to a positive environment for our -community include: - -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, - and learning from the experience -* Focusing on what is best not just for us as individuals, but for the - overall community - -Examples of unacceptable behavior include: - -* The use of sexualized language or imagery, and sexual attention or - advances of any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or email - address, without their explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Enforcement Responsibilities - -Community leaders are responsible for clarifying and enforcing our standards of -acceptable behavior and will take appropriate and fair corrective action in -response to any behavior that they deem inappropriate, threatening, offensive, -or harmful. - -Community leaders have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions that are -not aligned to this Code of Conduct, and will communicate reasons for moderation -decisions when appropriate. - -## Scope - -This Code of Conduct applies within all community spaces, and also applies when -an individual is officially representing the community in public spaces. -Examples of representing our community include using an official e-mail address, -posting via an official social media account, or acting as an appointed -representative at an online or offline event. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement. -All complaints will be reviewed and investigated promptly and fairly. - -All community leaders are obligated to respect the privacy and security of the -reporter of any incident. - -## Enforcement Guidelines - -Community leaders will follow these Community Impact Guidelines in determining -the consequences for any action they deem in violation of this Code of Conduct: - -### 1. Correction - -**Community Impact**: Use of inappropriate language or other behavior deemed -unprofessional or unwelcome in the community. - -**Consequence**: A private, written warning from community leaders, providing -clarity around the nature of the violation and an explanation of why the -behavior was inappropriate. A public apology may be requested. - -### 2. Warning - -**Community Impact**: A violation through a single incident or series -of actions. - -**Consequence**: A warning with consequences for continued behavior. No -interaction with the people involved, including unsolicited interaction with -those enforcing the Code of Conduct, for a specified period of time. This -includes avoiding interactions in community spaces as well as external channels -like social media. Violating these terms may lead to a temporary or -permanent ban. - -### 3. Temporary Ban - -**Community Impact**: A serious violation of community standards, including -sustained inappropriate behavior. - -**Consequence**: A temporary ban from any sort of interaction or public -communication with the community for a specified period of time. No public or -private interaction with the people involved, including unsolicited interaction -with those enforcing the Code of Conduct, is allowed during this period. -Violating these terms may lead to a permanent ban. - -### 4. Permanent Ban - -**Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an -individual, or aggression toward or disparagement of classes of individuals. - -**Consequence**: A permanent ban from any sort of public interaction within -the community. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], -version 2.0, available at -https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. - -Community Impact Guidelines were inspired by [Mozilla's code of conduct -enforcement ladder](https://github.com/mozilla/diversity). - -[homepage]: https://www.contributor-covenant.org - -For answers to common questions about this code of conduct, see the FAQ at -https://www.contributor-covenant.org/faq. Translations are available at -https://www.contributor-covenant.org/translations. diff --git a/CONTRIBUTING.MD b/CONTRIBUTING.MD deleted file mode 100644 index 8b722f0..0000000 --- a/CONTRIBUTING.MD +++ /dev/null @@ -1,10 +0,0 @@ -# HOW TO CONTRIBUTE: - -``` -1) Fork the repo and bring the repo in your local system -2) Create and switch to a separate branch -3) Add a codechef question solution that is not present in the repository in appropriate directory -4) List your question with solution in README.MD -4) commit and push your changes -``` -Congrats you made your PR successfully! diff --git a/Chef_And_His_Characters.java b/Chef_And_His_Characters.java deleted file mode 100644 index 6499273..0000000 --- a/Chef_And_His_Characters.java +++ /dev/null @@ -1,21 +0,0 @@ -import java.util.*; -import java.lang.*; -import java.io.*; -/* Name of the class has to be "Main" only if the class is public. */ -class Codechef -{ - public static void main (String[] args) throws java.lang.Exception - { - Scanner sc=new Scanner(System.in); - int n=sc.nextInt(); - Sets=new HashSet<>(); - for(int i=0;i -using namespace std; -int power(long long x, unsigned int y, int p) -{ - int res = 1; - - x = x % p; - - if (x == 0) return 0; - - while (y > 0) - { - - if (y & 1) - res = (res*x) % p; - - - y = y>>1; - x = (x*x) % p; - } - return res; -} -int main(){ -int t; -cin>>t; -while(t--) -{ - long long m = 1000000007; - int n,c=0; - cin>>n; - char a[n]; - for(int i=0;i>a[i]; - for (int i = 0; i < n; i++) - { - if(a[i]=='c' || a[i]=='g' || a[i]=='l' || a[i]=='r')c++; - } - if(c==0){ - cout<<1<= 0; i--) { - output[count[arr[i]] - 1] = arr[i]; - --count[arr[i]]; - } - - // Copy the output array to arr, so that arr now - // contains sorted characters - for (int i = 0; i < n; ++i) - arr[i] = output[i]; - } - - // Driver method - public static void main(String args[]) - { - CountSort ob = new CountSort(); - char arr[] = { 'g', 'e', 'e', 'k', 's', 'f', 'o', - 'r', 'g', 'e', 'e', 'k', 's' }; - - ob.sort(arr); - - System.out.print("Sorted character array is "); - for (int i = 0; i < arr.length; ++i) - System.out.print(arr[i]); - } -} -/*This code is contributed by Rajat Mishra */ diff --git a/Equal Difference Problem Code .cpp b/Equal Difference Problem Code .cpp deleted file mode 100644 index e9edbdf..0000000 --- a/Equal Difference Problem Code .cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#define ll long long int -#include -using namespace std; - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int test; - cin>>test; - while(test--){ - ll n; - cin>>n; - ll temp; - map mp; - for(ll i=0;i>temp; - mp[temp]++; - } - if(n<=2) cout<<0< -//#include -//#include -#pragma GCC optimize("Ofast") -#pragma GCC optimize ("O3") -#pragma GCC target ("avx") -#define vi vector -#define pii pair -#define vpii vector> -#define F first -#define S second -#define mp map -#define ump unordered_map -#define ll long long int -#define pb push_back -#define mod 1000000007 -#define int long long -#define pr(x) cout<=0;i--) -#define test int t; cin>>t; while(t--) -using namespace std; -//using namespace __gnu_pbds; -//typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key - -/*************************************************************************************************/ -void solve() -{ - int x,y; - cin>>x>>y; - (x%2==1 or (x==0 and y%2==1)) ? cout<<"NO\n":cout<<"YES\n"; -} -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - test - solve(); - return 0; -} diff --git a/Equalize_ab b/Equalize_ab deleted file mode 100644 index f254a4d..0000000 --- a/Equalize_ab +++ /dev/null @@ -1,27 +0,0 @@ -/*You are given two numbers AA and BB along with an integer XX. In one operation you can do one of the following: - -Set A = A + X and B = B - XB=B−X -Set A = A - X and B = B + XB=B+X - -Using above make a and b equal. -*/ - -#include -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - - while(t--){ - int a, b, x; - cin>>a>>b>>x; - - if(abs(a-b)%(2*x)==0 || a==b){ - cout<<"yes"<<"\n"; - } - else cout<<"no"<<"\n"; - } - return 0; -} diff --git a/Heart_Pattern_Printer.cpp b/Heart_Pattern_Printer.cpp deleted file mode 100644 index 6bd3b73..0000000 --- a/Heart_Pattern_Printer.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -using namespace std; - -int main() { - // heart star pattern - int size = 6; - - for (int i = size / 2; i < size; i += 2) { - // print first spaces - for (int j = 1; j < size - i; j += 2) { - cout << " "; - } - // print first stars - for (int j = 1; j < i + 1; j++) { - cout << "*"; - } - // print second spaces - for (int j = 1; j < size - i + 1; j++) { - cout << " "; - } - // print second stars - for (int j = 1; j < i + 1; j++) { - cout << "*"; - } - cout << "\n"; - } - // lower part - // inverted pyramid - for (int i = size; i > 0; i--) { - for (int j = 0; j < size - i; j++) { - cout << " "; - } - for (int j = 1; j < i * 2; j++) { - cout << "*"; - } - cout << "\n"; - } - return 0; -} diff --git a/Java/Arrays java b/Java/Arrays java deleted file mode 100644 index b171c48..0000000 --- a/Java/Arrays java +++ /dev/null @@ -1,182 +0,0 @@ -//Binary Search Algorithm - public static int binarySearch(int number[], int key) { - int start = 0; - int end = number.length - 1; - while (start <= end) { - int mid = (start + end) / 2; - if (number[mid] == key) { - return mid; - } - if (number[mid] < key) { - start = mid + 1; - } else { - end = mid - 1; - } - } - return -1; - } - - //Largest element in array - - public static int getlargest(int number[]){ - int largest=Integer.MAX_VALUE; - for(int i=0;i number[i]){ - largest=number[i]; - } - } - return largest; - } - //Smallest element in array - public static int getsmallest(int number[]){ - int smallest=Integer.MIN_VALUE; - for(int i=0;i=0;i--){ - rightMax[i]=Math.max(height[i],rightMax[i+1]); - } - - //loop - int trappedWater=0; - for(int i=0;i= '0' && c <= '9'); - - if (neg) - return -ret; - return ret; - } - - public long nextLong() throws IOException { - long ret = 0; - byte c = read(); - while (c <= ' ') - c = read(); - boolean neg = (c == '-'); - if (neg) - c = read(); - do { - ret = ret * 10 + c - '0'; - } while ((c = read()) >= '0' && c <= '9'); - if (neg) - return -ret; - return ret; - } - - public double nextDouble() throws IOException { - double ret = 0, div = 1; - byte c = read(); - while (c <= ' ') c = read(); - boolean neg = (c == '-'); - if (neg) c = read(); - - do { - ret = ret * 10 + c - '0'; - } while ((c = read()) >= '0' && c <= '9'); - if (c == '.') { - while ((c = read()) >= '0' && c <= '9') { - ret += (c - '0') / (div *= 10); - } - } - if (neg) return -ret; - return ret; - } - - private void fillBuffer() throws IOException { - bytesRead = din.read(buffer, bufferPointer = 0, - BUFFER_SIZE); - if (bytesRead == -1) - buffer[0] = -1; - } - private byte read() throws IOException { - if (bufferPointer == bytesRead) - fillBuffer(); - return buffer[bufferPointer++]; - } - - public void close() throws IOException { - if (din == null) - return; - din.close(); - } - } - static class Kattio extends PrintWriter { - private BufferedReader r; - private StringTokenizer st; - - // standard input - public Kattio() { this(System.in, System.out); } - public Kattio(InputStream i, OutputStream o) { - super(o); - r = new BufferedReader(new InputStreamReader(i)); - } - // USACO-style file input - public Kattio(String problemName) throws IOException { - super(new FileWriter(problemName + ".out")); - r = new BufferedReader(new FileReader(problemName + ".in")); - } - - // returns null if no more input - public String next() { - try { - while (st == null || !st.hasMoreTokens()) - st = new StringTokenizer(r.readLine()); - return st.nextToken(); - } catch (Exception e) { } - return null; - } - - public int nextInt() { return Integer.parseInt(next()); } - public double nextDouble() { return Double.parseDouble(next()); } - public long nextLong() { return Long.parseLong(next()); } - } - - static Kattio sc = new Kattio(); - static long mod = 998244353l; - static PrintWriter out =new PrintWriter(System.out); - - //Heapify function to maintain heap property. - public static void swap(int i,int j,int arr[]) { - int temp = arr[i]; - arr[i] = arr[j]; - arr[j] = temp; - } - public static void swap(int i,int j,long arr[]) { - long temp = arr[i]; - arr[i] = arr[j]; - arr[j] = temp; - } - public static void swap(int i,int j,char arr[]) { - char temp = arr[i]; - arr[i] = arr[j]; - arr[j] = temp; - } - static String endl = "\n" , gap = " "; - public static void main(String[] args)throws IOException { - int t = ri(); - // List list = new ArrayList<>(); - // int MAX = (int)4e4; - // for(int i =1;i<=MAX;i++) { - // if(isPalindrome(i + "")) list.add(i); - // } - // // System.out.println(list); - // long dp[] = new long[MAX +1]; - // dp[0] = 1; - // long mod = (long)(1e9+7); - // for(int x : list) { - // for(int i =1;i<=MAX;i++) { - // if(i >= x) { - // dp[i] += dp[i-x]; - // dp[i] %= mod; - // } - // } - // } - int MAK = (int)1e6; - boolean seive[] = new boolean[MAK]; - // Arrays.fill(seive , true); - // seive[1] = false; - // seive[0] = false; - // for (int i = 1; i < MAK; i++) { - // if(seive[i]) { - // for (int j = i+i; j < MAK; j+=i) { - // seive[j] = false; - // } - // } - - // } - // for (int i = 1; i <= MAK; i++) { - // seive[i] += seive[i - 1]; - // } - int test_case = 1; - while(t-->0) { - // out.write("Case #"+(test_case++)+": "); - solve(seive); - } - out.close(); - } - public static char getNew(char ch ,HashMap map) { - if(map.containsKey(ch) == false) return ch; - return getNew(map.get(ch),map); - } - public static void solve(boolean seive[])throws IOException { - int n = ri(); - int arr[][] = new int[n][2]; - for(int i = 0;i= n || nc >= n || vis[nr][nc] || a[nr][nc] == '1') continue; - dfs(nr , nc , a , vis); - } - } - public static char unequals(char ch ) { - if(ch == 'R') return 'G'; - if(ch == 'B') return 'R'; - if(ch == 'G') return 'B'; - return 'A'; - } - public static char unequal(char a,char b ) { - char s[] = {'R','G','B'}; - for(char ans : s) { - if(ans != a && ans != b) { - return ans; - } - } - return unequals(a); - } - public static int callfun(int index ,char s[] , char last) { - if(index >= s.length) return 0; - char t = s[0]; - int ans = Integer.MAX_VALUE; - if(s[index] == 'R') { - if(t == s[index]) { - ans = Math.min(callfun(index + 1 ,s , 'G')+ 1,ans); - ans = Math.min(callfun(index + 1 ,s , 'B')+ 1,ans); - } - else { - ans = Math.min(ans , callfun(index + 1 ,s , s[index])); - } - } - if(s[index] == 'G') { - if(t == s[index]) { - ans = Math.min(callfun(index + 1 ,s , 'R')+ 1,ans); - ans = Math.min(callfun(index + 1 ,s , 'B')+ 1,ans); - } - else { - ans = Math.min(ans , callfun(index + 1 ,s , s[index])); - } - } - if(s[index] == 'B') { - if(t == s[index]) { - ans = Math.min(callfun(index + 1 ,s , 'G')+ 1,ans); - ans = Math.min(callfun(index + 1 ,s , 'R')+ 1,ans); - } - else { - ans = Math.min(ans , callfun(index + 1 ,s , s[index])); - } - } - return ans; - } - public static int getMinMove(HashMap left , int id,int l , int r) { - return Math.min(Math.abs(left.get(id) -l ),Math.abs(left.get(id)-r))-1; - // if(left.containsKey(id)) { - // int at = left.size() - left.get(id); - // return Math.min(at ,right.size() + at - 1); - // } - // else { - // int at = right.size() - right.get(id); - // return Math.min(at , left.size() + at - 1); - // } - } - public static void print(int node ,HashMap> child, boolean vis[],List> ans,HashMap> map) { - if(vis[node]) return; - vis[node] = true; - List curans = new ArrayList<>(); - curans.add(child.get(node).size()); - curans.add(node); - for(int x : child.get(node)) { - if(vis[x]) continue; - vis[x] = true; - curans.add(x); - } - ans.add(curans); - for(int x : map.get(node)) { - if(vis[x]) continue; - print(x , child , vis,ans,map); - } - } - public static void callfun(int node ,HashMap> child,HashMap>map ) { - if(map.get(node).size() == 0) { - child.get(node).add(node); - return; - } - List list = new ArrayList<>(); - int cur = 0; - for(int next : map.get(node)) { - callfun(next, child , map); - } - for(int next : map.get(node)) { - if(cur < child.get(next).size()) { - cur = child.get(next).size(); - list = child.get(next); - } - } - child.get(node).add(node); - child.get(node).addAll(list); - } - public static int dfs(int node ,HashMap height, HashMap>map) { - if(map.get(node).size() == 0) { - height.put(node ,1); - return 0; - } - int cur = Integer.MAX_VALUE; - for(int next : map.get(node)) { - int cheigth = dfs(next , height , map); - cur = Math.min(cur , cheigth + 1); - } - height.put(node , cur); - return cur; - } - public static boolean check(String s) { - int cnt1 = 0 , cnt2 = 0; - for(char ch : s.toCharArray()) { - if(ch == '(') cnt1 = 1; - else cnt2 = 1; - } - return (cnt1 + cnt2 ) == 2; - } - public static String makeOps(String s) { - StringBuilder res = new StringBuilder(); - for(char ch : s.toCharArray()) { - if(ch == ')') res.append('('); - else res.append(')'); - } - return res.reverse().toString(); - } - public static String cmprs(String s) { - Stack stack = new Stack<>(); - for(char ch : s.toCharArray()) { - if(stack.size() == 0) stack.push(ch); - else { - if(ch == '(') stack.push(ch); - else { - if(stack.peek() == '(') stack.pop(); - else stack.push(ch); - } - } - } - StringBuilder res = new StringBuilder(); - while(stack.size() > 0) { - res.append(stack.pop()); - } - return res.reverse().toString(); - - } - public static boolean callfun(int n , Stack stack ,int i) { - if(n == 0) return true; - if(n == 1) { - stack.add(1); - return true; - } - if(i < 0) return false; - if((1< n) return callfun(n , stack , i-1); - stack.push(1<j; - } - // digit dp hint; - public static long callfun(String num , int N, int last ,int secondLast ,int bound ,long dp[][][][]) { - if(N == 1) { - if(last == -1 || secondLast == -1) return 0; - long answer = 0; - int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9; - for(int i = 0;i<=max;i++) { - if(last > secondLast && last > i) { - answer++; - } - if(last < secondLast && last < i) { - answer++; - } - } - return answer; - } - if(secondLast == -1 || last == -1 ){ - long answer = 0l; - int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9; - for(int i =0;i<=max;i++) { - int nl , nsl , newbound = bound==0?0:i==max?1:0; - if(last == - 1&& secondLast == -1 && i == 0) { - nl = -1 ; nsl = -1; - } - else { - nl = i;nsl = last; - } - - long temp = callfun(num , N-1 , nl , nsl ,newbound, dp); - answer += temp; - if(last != -1 && secondLast != -1 &&((last > secondLast && last > i)||(last < secondLast && last < i))) answer++; - } - return answer; - } - if(dp[N][last][secondLast][bound] != -1) return dp[N][last][secondLast][bound]; - long answer = 0l; - int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9; - for(int i =0;i<=max;i++) { - int nl , nsl , newbound = bound==0?0:i==max?1:0; - if(last == - 1&& secondLast == -1 && i == 0) { - nl = -1 ; nsl = -1; - } - else { - nl = i;nsl = last; - } - - long temp = callfun(num , N-1 , nl , nsl ,newbound,dp); - answer += temp; - if(last != -1 && secondLast != -1 &&((last > secondLast && last > i)||(last < secondLast && last < i))) answer++; - } - return dp[N][last][secondLast][bound] = answer; - } - public static Long callfun(int index ,int pair,int arr[],Long dp[][]) { - long mod = (long)998244353l; - if(index >= arr.length) return 1l; - if(dp[index][pair] != null) return dp[index][pair]; - Long sum = 0l , ans = 0l; - if(arr[index]%2 == pair) { - return dp[index][pair] = callfun(index + 1,pair^1 , arr,dp)%mod + callfun(index + 1 ,pair , arr , dp)%mod; - } - else { - return dp[index][pair] = callfun(index + 1,pair , arr,dp)%mod; - } - // for(int i =index;i= n) return true; - - if(s.charAt(0) == 'P') { - if(neg <= 0) return false; - return callfun(index + 1,n , neg-1 , pos , s.charAt(1) + "N"); - } - else { - if(pos <= 0) return false; - return callfun(index + 1 , n , neg , pos-1 , s.charAt(1) + "P"); - } - } - - public static void getPerm(int n , char arr[] , String s ,Listlist) { - if(n == 0) { - list.add(s); - return; - } - for(char ch : arr) { - getPerm(n-1 , arr , s+ ch,list); - } - } - public static int getLen(int i ,int j , char s[]) { - while(i >= 0 && j < s.length && s[i] == s[j]) { - i--; - j++; - } - i++; - j--; - if(i>j) return 0; - return j-i + 1; - } - public static int getMaxCount(String x) { - char s[] = x.toCharArray(); - int max = 0; - int n = s.length; - for(int i =0;i0 && b >0); - - - } - public static long callfun(int day , int k, int limit,int n) { - if(k > limit) return 0; - if(day > n) return 1; - long ans = callfun(day + 1 , k , limit, n)*k + callfun(day + 1,k+1,limit,n)*(k+1); - return ans; - } - - public static void primeDivisor(HashMapcnt , long num) { - for(long i = 2;i*i<=num;i++) { - while(num%i == 0) { - cnt.put(i ,(cnt.getOrDefault(i,0l) + 1)); - num /= i; - } - } - if(num > 2) { - cnt.put(num ,(cnt.getOrDefault(num,0l) + 1)); - } - } - - - public static boolean isSubsequene(char a[], char b[] ) { - int i =0 , j = 0; - while(i < a.length && j = b.length; - } - public static long fib(int n ,long M) { - if (n == 0) { - return 0; - } else if (n == 1) { - return 1; - } else { - long[][] mat = {{1, 1}, {1, 0}}; - mat = pow(mat, n-1 , M); - return mat[0][0]; - } - } - public static long[][] pow(long[][] mat, int n ,long M) { - if (n == 1) return mat; - else if (n % 2 == 0) return pow(mul(mat, mat , M), n/2 , M); - else return mul(pow(mul(mat, mat,M), n/2,M), mat , M); - } - static long[][] mul(long[][] p, long[][] q,long M) { - long a = (p[0][0]*q[0][0] + p[0][1]*q[1][0])%M; - long b = (p[0][0]*q[0][1] + p[0][1]*q[1][1])%M; - long c = (p[1][0]*q[0][0] + p[1][1]*q[1][0])%M; - long d = (p[1][0]*q[0][1] + p[1][1]*q[1][1])%M; - return new long[][] {{a, b}, {c, d}}; - } - public static long[] kdane(long arr[]) { - int n = arr.length; - long dp[] = new long[n]; - dp[0] = arr[0]; - long ans = dp[0]; - for(int i = 1;i r || high < l || high < low) return; - if(l <= low && high <= r) { - System.out.println("At " +low + " and " + high + " ans ttreeIndex " + treeIndex); - tree[treeIndex] += val; - return; - } - int mid = low + (high - low)/2; - update(low , mid , l , r , val , treeIndex*2 + 1, tree); - update(mid + 1 , high , l , r , val , treeIndex*2 + 2 , tree); - } - static int colx[] = {1 ,-1, 0,0 , 1,1,-1,-1}; - static int coly[] = {0 ,0, 1,-1,1,-1,1,-1}; - public static void reverse(char arr[]) { - int i =0 , j = arr.length-1; - while(i < j) { - swap(i , j , arr); - i++; - j--; - } - } - public static long[] reverse(long arr[]) { - long newans[] = arr.clone(); - int i =0 , j = arr.length-1; - while(i < j) { - swap(i , j , newans); - i++; - j--; - } - return newans; - } - public static void reverse(int arr[]) { - int i =0 , j = arr.length-1; - while(i < j) { - swap(i , j , arr); - i++; - j--; - } - } - - public static long inverse(long x , long mod) { - return pow(x , mod -2 , mod); - } - public static int maxArray(int arr[]) { - int ans = arr[0] , n = arr.length; - for(int i =1;i 0) { - ans++; - num = num&(num-1); - } - return ans; - } - public static boolean isValid(int x ,int y , int n,char arr[][],boolean visited[][][][]) { - return x>=0 && x=0 && y b) return 0; - // if(l > r) return 0; - // if(tree[node].min >= a && tree[node].max <= b) { - // return tree[node].count; - // } - // int mid = l + (r-l)/2; - // int ans = query(node*2 ,l , mid ,a , b , tree) + query(node*2 +1,mid + 1, r , a , b, tree); - // return ans; - // } - // // segment tree update over range - // public static void update(int node, int i , int j ,int l , int r,long value, long arr[] ) { - // if(l >= i && j >= r) { - // arr[node] += value; - // return; - // } - // if(j < l|| r < i) return; - // int mid = l + (r-l)/2; - // update(node*2 ,i ,j ,l,mid,value, arr); - // update(node*2 +1,i ,j ,mid + 1,r, value , arr); - // } - - public static long pow(long a , long b , long mod) { - if(b == 1) return a; - if(b == 0) return 1; - long ans = pow(a , b/2 , mod)%mod; - if(b%2 == 0) { - return (ans*ans)%mod; - } - else { - return ((ans*ans)%mod*a)%mod; - } - } - public static long pow(long a , long b ) { - if(b == 1) return a; - if(b == 0) return 1; - long ans = pow(a , b/2); - if(b%2 == 0) { - return (ans*ans); - } - else { - return ((ans*ans)*a); - } - } - - - public static boolean isVowel(char ch) { - if(ch == 'a' || ch == 'e'||ch == 'i' || ch == 'o' || ch == 'u') return true; - if((ch == 'A' || ch == 'E'||ch == 'I' || ch == 'O' || ch == 'U')) return true; - return false; - } - - - - public static int getFactor(int num) { - if(num==1) return 1; - int ans = 2; - int k = num/2; - for(int i = 2;i<=k;i++) { - if(num%i==0) ans++; - } - return Math.abs(ans); - } - - public static int[] readarr()throws IOException { - int n = sc.nextInt(); - int arr[] = new int[n]; - for(int i =0;i s=new ArrayList<>(); - - public static boolean isEmpty(){ - return s.size()==0; - } - public static void push(int data){ - s.add(data); - } - static int pop(){ - if(s.isEmpty()){ - return -1; - } - int top=s.get(s.size()-1); - s.remove(s.size()-1); - return top; - } - public int peek(){ - if(s.isEmpty()){ - return -1; - } - return s.get(s.size()-1); - } - - } - - //Implenenting stack using linkedlist - - static class Node{ - int data; - Node next; - Node(int data){ - this.data=data; - this.next=null; - } - } - static class Stack{ - static Node head=null; - - public static boolean isEmpty(){ - return head==null; - } - - static void push(int data){ - Node newNode=new Node(data); - - if(isEmpty()){ - head=newNode; - return; - } - newNode.next=head; - head=newNode; - } - - static int pop(){ - if(isEmpty()){ - return -1; - } - int top=head.data; - head=head.next; - return top; - } - - static int peek(){ - if(isEmpty()){ - return -1; - } - return head.data; - } - } - - //Dublicate parenthesis - public static boolean isDublicate(String str){ - Stack s=new Stack<>(); - for(int i=0;i s ,int data){ - - if(s.isEmpty()){ - s.push(data); - return; - } - - int top=s.pop(); - pushatBottom(s, data); - s.push(top); - } - //reverse stack - public static void pushBottom(Stack s, int data) { - if (s.isEmpty()) { - s.push(data); - return; - } - int top = s.pop(); - pushBottom(s, data); - s.push(top); - } - - public static void reverseStack(Stack s) { - if (s.isEmpty()) { - return; - } - int top = s.pop(); - reverseStack(s); - pushBottom(s, top); - } - //reverse string using stack - public static String reverseString(String str){ - Stack s=new Stack<>(); - int idx=0; - while(idxarr[j+1]){ - int temp = arr[j]; - arr[j] = arr[j + 1]; - arr[j + 1] = temp; - } - } - - } - } - - - //optimise bubble sort - public static void modifiedbubbleSort(int arr[]) { - for (int turn = 0; turn < arr.length; turn++) { - boolean swapped=false; - for (int j = 0; j < arr.length - 1; j++) { - if(arr[j]>arr[j+1]){ - int temp = arr[j]; - arr[j] = arr[j + 1]; - arr[j + 1] = temp; - swapped=true; - } - } - if(swapped==false){ - break; - } - } - } - - //Insertion sort - // for accending order - public static void insertionSort(int arr[]) { - for (int i = 1; i < arr.length; i++) { - int curr = arr[i]; - int prev = i - 1; - while (prev >= 0 && arr[prev] > curr) { - arr[prev + 1] = arr[prev]; - prev--; - } - arr[prev + 1] = curr; - } - } - - // for decending order - public static void insertionSort2(int arr[]) { - for (int i = 1; i < arr.length; i++) { - int curr = arr[i]; - int prev = i - 1; - while (prev >= 0 && arr[prev] < curr) { - arr[prev + 1] = arr[prev]; - prev--; - } - arr[prev + 1] = curr; - } - } - - //Selection Sort - public static void selectionSort(int arr[]){ - for(int i=0;iarr[j]){ - currPos=j; - } - } - int temp=arr[currPos]; - arr[currPos]=arr[i]; - arr[i]=temp; - } - } - public static void printArr(int arr[]) { - for (int i = 0; i < arr.length; i++) { - System.out.print( arr[i] +" "); - } - System.out.println(); - } - - // Merge Sort - public static void mergeSort(int arr[],int s,int e){ - if(s>=e){ - return; - } - int mid=s+(e-s)/2; - mergeSort(arr, s, mid); - mergeSort(arr,mid+1, e); - merge(arr,s,mid,e); - } - - public static void merge(int arr[],int s,int mid,int e){ - int temp[]=new int[e-s+1]; - int i=s; - int j=mid +1; - int k=0; - - while(i<=mid && j<= e){ - if(arr[i]=e){ - return; - } - - int Indx= partitions(arr, s ,e); //last element - - quickSort(arr, s, Indx-1); //left - - quickSort(arr, Indx+1, e); //right - - } - - public static int partitions(int arr[],int s,int e){ - int pivot=arr[e]; - int i=s-1; - - for(int j=s;j -#include - -int main() -{ - int a[10],i,n,min,max; - - printf("Enter size of the array : "); - scanf("%d",&n); - - printf("Enter elements in array : "); - for(i=0; ia[i]) - min=a[i]; - if(max -using namespace std; - -#define ll long long int - -bool isPowerOfTwo (int x) -{ - /* First x in the below expression is for the case when x is 0 */ - return x && (!(x&(x-1))); -} - -void solve(){ - int a, b; - cin >> a >> b; - if(a > b){ - int temp=a; - a = b; - b = temp; - } - // a <= b - int x = __gcd(a, b), c = (b/x); - if(x == a && isPowerOfTwo(c) ) - cout << "YES\n"; - else - cout << "NO\n"; -} - -int main() { - ios_base::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - ll t; - cin >> t; - while(t--) - solve(); - return 0; -} - - diff --git a/Python/AI Analysing Code.py b/Python/AI Analysing Code.py deleted file mode 100644 index 405071e..0000000 --- a/Python/AI Analysing Code.py +++ /dev/null @@ -1,6 +0,0 @@ -# cook your dish here -c=int(input()) -if c<=1000: - print("yes") -else: - print("no") \ No newline at end of file diff --git a/Python/ANSLEAK.py b/Python/ANSLEAK.py deleted file mode 100644 index f2a4604..0000000 --- a/Python/ANSLEAK.py +++ /dev/null @@ -1,17 +0,0 @@ -from random import randint -def leakans(a, n, m, k): - ans = [0]*n - for t in range(n): - g = a[t][t] - ans[t] = g - return ans - -test = int(input()) -for i in range(test): - n, m, k = map(int, input().split()) - a = [] - for j in range(n): - p = list(map(int, input().split())) - a.append(p) - z = leakans(a, n, m, k) - print(*z) \ No newline at end of file diff --git a/Python/ATM.py b/Python/ATM.py deleted file mode 100644 index 8c36be5..0000000 --- a/Python/ATM.py +++ /dev/null @@ -1,6 +0,0 @@ -n, atm = map(float, input().split()) -n = int(n) -if n + 0.5 <= atm and n % 5 == 0: - print(float(atm - n - 0.5)) -else: - print(float(atm)) diff --git a/Python/Avoid Fix Point.py b/Python/Avoid Fix Point.py deleted file mode 100644 index 30f5d63..0000000 --- a/Python/Avoid Fix Point.py +++ /dev/null @@ -1,9 +0,0 @@ -for _ in range(int(input())): - n = int(input()) - l = list(map(int, input().split())) - k = 0 - for i in range(len(l)): - Value = 1 + i + k - if Value == l[i]: - k += 1 - print(k) diff --git a/Python/Biryani.py b/Python/Biryani.py deleted file mode 100644 index 8137a96..0000000 --- a/Python/Biryani.py +++ /dev/null @@ -1,4 +0,0 @@ -t=int(input()) -for i in range(t): - x,y=map(int,input().split()) - print(x*y) diff --git a/Python/COMPRESSVD.py b/Python/COMPRESSVD.py deleted file mode 100644 index 489733a..0000000 --- a/Python/COMPRESSVD.py +++ /dev/null @@ -1,31 +0,0 @@ -def answer_finder(): - n = int(input()) - a = input() - a = a.split() - if n == 1: - print(n) - - elif n ==2: - if a[0] == a[1]: - print(1) - else: - print(2) - else: - count = 0 - for i in range(1,n): - if a[i] == a[i-1]: - a[i]=a[i-1] - count+=1 - - elif i != n-1 and a[i] == a[i+1]: - count+=1 - a[i]=a[i-1] - - - print(len(a)-count) - -test_cases = int(input()) - -while test_cases: - test_cases -= 1 - answer_finder() diff --git a/Python/Car or Bus.py b/Python/Car or Bus.py deleted file mode 100644 index 54c9d37..0000000 --- a/Python/Car or Bus.py +++ /dev/null @@ -1,8 +0,0 @@ -for _ in range(int(input())): - b, c = map(int, input().split()) - if c < b: - print("Car") - elif b < c: - print("Bike") - else: - print("SAME") diff --git a/Python/Careless Chef.py b/Python/Careless Chef.py deleted file mode 100644 index 4c5277b..0000000 --- a/Python/Careless Chef.py +++ /dev/null @@ -1,8 +0,0 @@ -for _ in range(int(input())): - n = int(input()) - l = list(map(int, input().split())) - s = sum(l) - if s % 2 == 0: - print("YES") - else: - print("NO") diff --git a/Python/Cats and a Mouse.py b/Python/Cats and a Mouse.py deleted file mode 100644 index 9572fe7..0000000 --- a/Python/Cats and a Mouse.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/python3 - -import math -import os -import random -import re -import sys - -# Complete the catAndMouse function below. -def catAndMouse(x, y, z): - if abs(x - z) < abs(y - z): - return "Cat A" - elif abs(x - z) > abs(y - z): - return "Cat B" - else: - return "Mouse C" - - -if __name__ == "__main__": - fptr = open(os.environ["OUTPUT_PATH"], "w") - - q = int(input()) - - for q_itr in range(q): - xyz = input().split() - - x = int(xyz[0]) - - y = int(xyz[1]) - - z = int(xyz[2]) - - result = catAndMouse(x, y, z) - - fptr.write(result + "\n") - - fptr.close() diff --git a/Python/Chef and NextGen.py b/Python/Chef and NextGen.py deleted file mode 100644 index 3749802..0000000 --- a/Python/Chef and NextGen.py +++ /dev/null @@ -1,6 +0,0 @@ -for _ in range(int(input())): - a, b, x, y = map(int, input().split()) - if (x * y) >= (a * b): - print("YES") - else: - print("NO") diff --git a/Python/Ciel and A-B Problem.py b/Python/Ciel and A-B Problem.py deleted file mode 100644 index 653963e..0000000 --- a/Python/Ciel and A-B Problem.py +++ /dev/null @@ -1,21 +0,0 @@ -#include -using namespace std; - - -int main(){ - int a,b,res,last; - cin>>a>>b; - - res=a-b; - last=res%10; - - if(last==9){ - res=res-1; - } - else{ - res=res+1; - } - - cout< b[0]: - alic += 1 - else: - bob += 1 - if a[1] == b[1]: - pass - elif a[1] > b[1]: - alic += 1 - else: - bob += 1 - if a[2] == b[2]: - pass - elif a[2] > b[2]: - alic += 1 - else: - bob += 1 - return alic, bob - - -if __name__ == "__main__": - fptr = open(os.environ["OUTPUT_PATH"], "w") - - a = list(map(int, input().rstrip().split())) - - b = list(map(int, input().rstrip().split())) - - result = compareTriplets(a, b) - - fptr.write(" ".join(map(str, result))) - fptr.write("\n") - - fptr.close() diff --git a/Python/Count The Notebook.py b/Python/Count The Notebook.py deleted file mode 100644 index 38a6c9f..0000000 --- a/Python/Count The Notebook.py +++ /dev/null @@ -1,6 +0,0 @@ -for _ in range(int(input())): - n = int(input()) - no_of_pages = n * 1000 - no_of_nb = no_of_pages / 100 - - print(int(no_of_nb)) diff --git a/Python/Daanish and Problems.py b/Python/Daanish and Problems.py deleted file mode 100644 index 1faf136..0000000 --- a/Python/Daanish and Problems.py +++ /dev/null @@ -1,8 +0,0 @@ -for _ in range(int(input())): - l = list(map(int, input().split())) - k = int(input()) - i = 9 - while k >= l[i]: - k -= l[i] - i -= 1 - print(i + 1) diff --git a/Python/Day of the Programmer.py b/Python/Day of the Programmer.py deleted file mode 100644 index 6cdcfa1..0000000 --- a/Python/Day of the Programmer.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/python3 - -import math -import os -import random -import re -import sys - -# -# Complete the 'dayOfProgrammer' function below. -# -# The function is expected to return a STRING. -# The function accepts INTEGER year as parameter. -# - - -def dayOfProgrammer(year): - if year == 1918: - return "26.09.1918" - if year % 4 == 0 and (year < 1918 or year % 400 == 0 or year % 100 != 0): - return "12.09.%s" % year - return "13.09.%s" % year - - -if __name__ == "__main__": - fptr = open(os.environ["OUTPUT_PATH"], "w") - - year = int(input().strip()) - - result = dayOfProgrammer(year) - - fptr.write(result + "\n") - - fptr.close() diff --git a/Python/Diagonal Difference.py b/Python/Diagonal Difference.py deleted file mode 100644 index 2cc1278..0000000 --- a/Python/Diagonal Difference.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/python3 - -import math -import os -import random -import re -import sys - -# -# Complete the 'diagonalDifference' function below. -# -# The function is expected to return an INTEGER. -# The function accepts 2D_INTEGER_ARRAY arr as parameter. -# - - -def diagonalDifference(arr): - s1, s2 = 0, 0 - for i in range(n): - for j in range(n): - if i == j: - s1 += arr[i][j] - if i == n - j - 1: - s2 += arr[i][j] - return abs(s1 - s2) - - -if __name__ == "__main__": - fptr = open(os.environ["OUTPUT_PATH"], "w") - - n = int(input().strip()) - - arr = [] - - for _ in range(n): - arr.append(list(map(int, input().rstrip().split()))) - - result = diagonalDifference(arr) - - fptr.write(str(result) + "\n") - - fptr.close() diff --git a/Python/Enormous Input Test.py b/Python/Enormous Input Test.py deleted file mode 100644 index 5dbae19..0000000 --- a/Python/Enormous Input Test.py +++ /dev/null @@ -1,6 +0,0 @@ -n, k = map(int, input().split()) -c = 0 -for _ in range(n): - if int(input()) % k == 0: - c += 1 -print(c) diff --git a/Python/GCD and LCM.py b/Python/GCD and LCM.py deleted file mode 100644 index ce80375..0000000 --- a/Python/GCD and LCM.py +++ /dev/null @@ -1,6 +0,0 @@ -import math - -for _ in range(int(input())): - a, b = map(int, input().split()) - gcd = math.gcd(a, b) - print(gcd, int(a * b / gcd)) diff --git a/Python/Gross Salary.py b/Python/Gross Salary.py deleted file mode 100644 index 66d55c8..0000000 --- a/Python/Gross Salary.py +++ /dev/null @@ -1,6 +0,0 @@ -for _ in range(int(input())): - n = int(input()) - if n < 1500: - print(n + (n * 0.1) + (n * 0.9)) - else: - print(n + (500) + (n * 0.98)) diff --git a/Python/Hostel Room.py b/Python/Hostel Room.py deleted file mode 100644 index de433d7..0000000 --- a/Python/Hostel Room.py +++ /dev/null @@ -1,8 +0,0 @@ -for _ in range(int(input())): - n, x = map(int, input().split()) - l = list(map(int, input().split())) - a, r = x, x - for i in range(n): - r += l[i] - a = max(a, r) - print(a) diff --git a/Python/How Many Digits.py b/Python/How Many Digits.py deleted file mode 100644 index c4a4249..0000000 --- a/Python/How Many Digits.py +++ /dev/null @@ -1,5 +0,0 @@ -n = input() -if len(n) > 3: - print("More than 3 digits") -else: - print(len(n)) diff --git a/Python/Left Rotation.py b/Python/Left Rotation.py deleted file mode 100644 index 9355ad0..0000000 --- a/Python/Left Rotation.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/python3 - -import math -import os -import random -import re -import sys - - -def rotateLeft(d, arr): - for i in range(d): - a = arr[0] - arr.pop(0) - arr.append(a) - result = arr.copy() - return result - - -if __name__ == "__main__": - fptr = open(os.environ["OUTPUT_PATH"], "w") - - first_multiple_input = input().rstrip().split() - - n = int(first_multiple_input[0]) - - d = int(first_multiple_input[1]) - - arr = list(map(int, input().rstrip().split())) - - result = rotateLeft(d, arr) - - fptr.write(" ".join(map(str, result))) - fptr.write("\n") - - fptr.close() diff --git a/Python/Length of Last Word b/Python/Length of Last Word deleted file mode 100644 index c738f9e..0000000 --- a/Python/Length of Last Word +++ /dev/null @@ -1,7 +0,0 @@ -txt = input() -x=txt.split() -empty=0 -if empty: - print(0) -else: - print(len(x[-1])) diff --git a/Python/List Comprehensions.py b/Python/List Comprehensions.py deleted file mode 100644 index dd74f70..0000000 --- a/Python/List Comprehensions.py +++ /dev/null @@ -1,12 +0,0 @@ -if __name__ == "__main__": - x = int(input()) - y = int(input()) - z = int(input()) - n = int(input()) - ans = [] - for i in range(x + 1): - for j in range(y + 1): - for k in range(z + 1): - if i + j + k != n: - ans.append([i, j, k]) - print(ans) diff --git a/Python/Longest AND Subarray.py b/Python/Longest AND Subarray.py deleted file mode 100644 index 5ed3c82..0000000 --- a/Python/Longest AND Subarray.py +++ /dev/null @@ -1,15 +0,0 @@ -from math import log2 as lg -tc= int(input()) -for i in range(tc): - n=int(input()) - lwr=int(lg(n)) - if n==1: - print(1) - continue - if lg(n)-lwr==0.0: - ans=n-(2**(lwr-1)) - print(ans) - else: - a=n-(2**(lwr))+1 - b=(2 ** (lwr))-(2** (lwr-1)) - print(max(a,b)) diff --git a/Python/Mahasena.py b/Python/Mahasena.py deleted file mode 100644 index b3e1e8c..0000000 --- a/Python/Mahasena.py +++ /dev/null @@ -1,12 +0,0 @@ -n = int(input()) -l = list(map(int, input().split())) -e, o = 0, 0 -for i in l: - if i % 2 == 0: - e += 1 - else: - o += 1 -if e > o: - print("READY FOR BATTLE") -else: - print("NOT READY") diff --git a/Python/Maximise the Subsequence Sum.py b/Python/Maximise the Subsequence Sum.py deleted file mode 100644 index 9591c49..0000000 --- a/Python/Maximise the Subsequence Sum.py +++ /dev/null @@ -1,14 +0,0 @@ -for _ in range(int(input())): - n, k = map(int, input().split()) - l = list(map(int, input().split())) - l.sort() - ans = 0 - for i in range(k): - if l[i] > 0: # if ele is greater than 0 stop - break - elif l[i] < 0: # if not then make it postive - l[i] *= -1 - for i in range(n): - if l[i] > 0: # add all postive ele from list - ans += l[i] - print(ans) diff --git a/Python/Maximum Weight Difference.py b/Python/Maximum Weight Difference.py deleted file mode 100644 index 5dfb5b3..0000000 --- a/Python/Maximum Weight Difference.py +++ /dev/null @@ -1,8 +0,0 @@ -for _ in range(int(input())): - n, k = map(int, input().split()) - l = list(map(int, input().split())) - l.sort() - if k <= n // 2: - print(abs(sum(l[:k]) - sum(l[k:]))) - else: - print(abs(sum(l[n - k :]) - sum(l[: n - k]))) diff --git a/Python/Migratory Birds.py b/Python/Migratory Birds.py deleted file mode 100644 index 9defc8a..0000000 --- a/Python/Migratory Birds.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/python3 - -import math -import os -import random -import re -import sys -import collections - -# -# Complete the 'migratoryBirds' function below. -# -# The function is expected to return an INTEGER. -# The function accepts INTEGER_ARRAY arr as parameter. -# - - -def migratoryBirds(arr): - cou = [0] * 6 - for t in arr: - cou[t] += 1 - res = cou.index(max(cou)) - return res - - -if __name__ == "__main__": - fptr = open(os.environ["OUTPUT_PATH"], "w") - - arr_count = int(input().strip()) - - arr = list(map(int, input().rstrip().split())) - - result = migratoryBirds(arr) - - fptr.write(str(result) + "\n") - - fptr.close() diff --git a/Python/Most Frequency.py b/Python/Most Frequency.py deleted file mode 100644 index c28a519..0000000 --- a/Python/Most Frequency.py +++ /dev/null @@ -1,15 +0,0 @@ -dicti = {} - - -def most_frequent(s): - for i in s: - if i not in dicti: - dicti[i] = 1 - else: - dicti[i] += 1 - return dicti - - -res = most_frequent("mississippi") -for keys in sorted(res, key=res.get, reverse=True): - print(keys, "=", res[keys]) diff --git a/Python/Penalty Shootout 2.py b/Python/Penalty Shootout 2.py deleted file mode 100644 index f9696de..0000000 --- a/Python/Penalty Shootout 2.py +++ /dev/null @@ -1,35 +0,0 @@ -T = int(input()) -for t in range(T): - N = int(input()) - S = input() - L = 2*N - - currScoreA = 0 - currScoreB = 0 - leftShotA = N - leftShotB = N - - winVar = L - - for i in range(L): - if S[i] == '1': - if i % 2 == 0: - currScoreA += 1 - else: - currScoreB += 1 - - if i % 2 == 0: - leftShotA = leftShotA - 1 - else: - leftShotB = leftShotB - 1 - - if currScoreA > currScoreB + leftShotB: - winVar = i + 1 - break - if currScoreB > currScoreA + leftShotA: - winVar = i + 1 - break - - print(winVar) - - diff --git a/Python/Possible Victory.py b/Python/Possible Victory.py deleted file mode 100644 index 43c43c4..0000000 --- a/Python/Possible Victory.py +++ /dev/null @@ -1,8 +0,0 @@ -r, o, c = map(int, input().split()) -remaining_over = 20 - o -maxscore = remaining_over * 6 * 6 -total_score = c + maxscore -if total_score > r: - print("YES") -else: - print("NO") diff --git a/Python/Racing Horses.py b/Python/Racing Horses.py deleted file mode 100644 index 49489cc..0000000 --- a/Python/Racing Horses.py +++ /dev/null @@ -1,10 +0,0 @@ -# Racing Horses -for _ in range(int(input())): - n = int(input()) - l = list(map(int, input().split())) - l.sort() - m = l[1] - l[0] - for j in range(1, n): - if l[j] - l[j - 1] < m: - m = l[j] - l[j - 1] - print(m) diff --git a/Python/Reverse The Number.py b/Python/Reverse The Number.py deleted file mode 100644 index 7182394..0000000 --- a/Python/Reverse The Number.py +++ /dev/null @@ -1,5 +0,0 @@ -s = input() # taking num as string -res = "" -for i in s: - res = i + res -print(int(res)) diff --git a/Python/Runner-Up Score.py b/Python/Runner-Up Score.py deleted file mode 100644 index 892f179..0000000 --- a/Python/Runner-Up Score.py +++ /dev/null @@ -1,4 +0,0 @@ -n = int(input()) - arr = map(int, input().split()) - print(sorted(list(set(arr)))[-2]) - diff --git a/Python/Smallest Numbers of Notes.py b/Python/Smallest Numbers of Notes.py deleted file mode 100644 index 6fb51dd..0000000 --- a/Python/Smallest Numbers of Notes.py +++ /dev/null @@ -1,8 +0,0 @@ -notes = [100, 50, 10, 5, 2, 1] -for _ in range(int(input())): - m = 0 - n = int(input()) - for i in notes: - m = m + n // i - n = n % i - print(m) diff --git a/Python/Suspense-String.py b/Python/Suspense-String.py deleted file mode 100644 index 7d217ee..0000000 --- a/Python/Suspense-String.py +++ /dev/null @@ -1,20 +0,0 @@ -t=int(input()) - -for i in range(t): - T="" - length=int(input()) - N=input() - i,j=0,length-1 - while(j>=i): - - T=N[i]+T if N[i]=='0' else T+N[i] - i=i+1 - - if(i-1==j): - break - - T=T+N[j] if N[j]=='0' else N[j]+T - j=j-1 - - print(T) - diff --git a/Python/Total Expenses.py b/Python/Total Expenses.py deleted file mode 100644 index da46ede..0000000 --- a/Python/Total Expenses.py +++ /dev/null @@ -1,10 +0,0 @@ -for _ in range(int(input())): - q, p = map(int, input().split()) - if q <= 1000: - ans = q * p - print("%.6f" % ans) - else: - ans = q * p - dic = ans * 0.1 - res = ans - dic - print("%.6f" % res) diff --git a/Python/Turbo Sort.py b/Python/Turbo Sort.py deleted file mode 100644 index 231c04c..0000000 --- a/Python/Turbo Sort.py +++ /dev/null @@ -1,5 +0,0 @@ -li = [] -for _ in range(int(input())): - li.append(int(input())) -for i in sorted(li): - print(i) diff --git a/Python/World Chess Championsh.py b/Python/World Chess Championsh.py deleted file mode 100644 index 7693e0f..0000000 --- a/Python/World Chess Championsh.py +++ /dev/null @@ -1,14 +0,0 @@ -for _ in range(int(input())): - x = int(input()) - s = input() - c = s.count("C") - d = s.count("D") - n = s.count("N") - c = c * 2 + d - n = n * 2 + d - if c > n: - print(60 * x) - elif c < n: - print(40 * x) - else: - print(55 * x) diff --git a/Python/XOR Palindrome.py b/Python/XOR Palindrome.py deleted file mode 100644 index edf010a..0000000 --- a/Python/XOR Palindrome.py +++ /dev/null @@ -1,18 +0,0 @@ -for _ in range(int(input())): - n = int(input()) - s = input() - a, b = 0, 0 - for i in s: - if i == "0": - a += 1 - else: - b += 1 - if n % 2 == 0: - if a == b: - print("YES") - elif a % 2 == 0 and b % 2 == 0: - print("YES") - else: - print("NO") - else: - print("YES") diff --git a/Python/Yet Another Palindrome Problem.py b/Python/Yet Another Palindrome Problem.py deleted file mode 100644 index 9ad3140..0000000 --- a/Python/Yet Another Palindrome Problem.py +++ /dev/null @@ -1,24 +0,0 @@ -def mgc(arr,n): - if arr == arr[::-1]: - return 0 - temp = [] - for i in range(n//2): - x = arr[n-i-1] - arr[i] - if x<0: - return -1 - else: - temp.append(x) - #print(temp) - ans = 0 - for i in range(len(temp)-1,-1,-1): - if ans > temp[i]: - return -1 - ops = (temp[i]-ans) - ans += ops - return ans - - -for _ in range(int(input())): - n = int(input()) - arr = list(map(int,input().split())) - print(mgc(arr,n)) \ No newline at end of file diff --git a/Python/weight balance.py b/Python/weight balance.py deleted file mode 100644 index 13a0a94..0000000 --- a/Python/weight balance.py +++ /dev/null @@ -1,12 +0,0 @@ -# https://www.codechef.com/submit/WEIGHTBL - - -for i in range(int(input())): # number of test case - l=list(map(int,input().split())) # taking inputs in a list - inc=l[1]-l[0] - minR=l[2]*l[4] - maxR=l[3]*l[4] - if(inc==minR or inc==maxR or (inc>minR and inc -

Practice-Problems

- - -### This repository contains solutions for problems on codechef.com -Check how to contribute to this repository [Contribution](/CNTRIBUTING.MD) -
- -## C++ - -| S.No. | Question | Solution | -|:------|:--------| :--------| -|1. | [CMASKS](https://www.codechef.com/problems/CMASKS) |[Chef and Masks](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/chef_and_masks.cpp) | -|2. | [SMOKE](https://www.codechef.com/START26B/problems/SMOKE/) |[Control The Pollution](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Control%20The%20Pollution.cpp) | -|3. | codechef URL |[Fibonacci Series](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Fibonacci_series.cpp) | -|4. | [PIZZA_BURGER](https://www.codechef.com/COOK137C/problems/PIZZA_BURGER/) |[Hungry Ashish](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Hungry%20Ashish.cpp) | -|5. | [MASKPOL](https://www.codechef.com/problems/MASKPOL) |[Mask Policy](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Mask%20Policy.cpp) | -|6. | [MEANMAX](https://www.codechef.com/problems/MEANMAX) |[Mean Maximization](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Mean%20Maximization.cpp) | -|7. | [MRGSRT](https://www.codechef.com/problems/MRGSRT) |[Merge Sort](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Mergesort.cpp) | -|8. | [NOPAL](https://www.codechef.com/problems/NOPAL) |[Palindromes Not Allowed](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Palindromes%20Not%20Allowed%20.cpp) | -|9. | [SYNSARA4](https://www.codechef.com/problems/SYNSARA4) |[Sum of Array](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/sumofarray.cpp) | -|10. | [FACTZERO](https://www.codechef.com/problems/FACTZERO) |[Zero Factorial](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Zero%20Factorial.cpp) | -|11. | [BALLBOX](https://www.codechef.com/submit/BALLBOX) |[Balls And Boxes](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Balls_and_Boxes.cpp) | -|12. | [CARCHOICE](https://www.codechef.com/START28C/problems/CARCHOICE/) |[Car Choice](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Car_choice.cpp) | -|13. | [SNCKYEAR](https://www.codechef.com/problems/SNCKYEAR) |[Chef and Snackdown](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Chef_and_Snackdown.cpp) | -|14. | [CHSFORMT](https://www.codechef.com/problems/CHSFORMT) |[Chess Format](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Chess_Format.cpp) | -|15. | [SUNDAY](https://www.codechef.com/problems/SUNDAY) |[Count The Holidays](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Count_the_holidays.cpp) | -|16. | [FACEDIR](https://www.codechef.com/START11C/problems/FACEDIR/) |[Find The Direction](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Find_the_direction.cpp) | -|17. | [GOLMINE](https://www.codechef.com/problems/GOLMINE) |[Gold Mining](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Gold_mining.cpp) | -|18. | [ODDSEVENS](https://www.codechef.com/COOK135C/problems/ODDSEVENS/) |[Odds And Evens](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Odds_and_Evens.cpp) | -|19. | [OLYRANK](https://www.codechef.com/AUG21C/problems/OLYRANK/) |[Olympics Ranking](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Olympics_ranking.cpp) | -|20. | [PENALTY](https://www.codechef.com/problems/PENALTY) |[Penalty Shots](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Penalty_shots.cpp) | -|21. | [SAVWATER](https://www.codechef.com/SPYB21C/problems/SAVWATER/) |[Save Water Save Life](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Save_water_save_life.cpp) | -|22. | [THREEQ](https://www.codechef.com/problems/THREEQ) |[The Old Saint And Three Questions](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/The_old_saint_and_three_questions.cpp) | -|23. | [VDATES](https://www.codechef.com/problems/VDATES) |[Vaccine Dates](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Vaccine_dates.cpp) | -|24. | [CDBSTR06](https://www.codechef.com/problems/CDBSTR06) |[Maximum Subarray](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/Maximum_Subarray.cpp) | -|25. | [B01T](https://www.codechef.com/problems/B01T) |[Balanced 0-1 Tree](https://github.com/Kdeveloper2000/CodeChef/blob/Graph/CC/C%2B%2B/Balanced1Tree.cpp)| -|26. | [CHFINVNT](https://www.codechef.com/AUG21C/problems/CHFINVNT) | [Chef And Bulb Invention](https://github.com/Sahiljawale/CodeChef/blob/main/C%2B%2B/chef_and_bulb_invention.cpp) -
- -## Python - -| S.No. | Question | Solution | -|:------|:--------| :--------| -|1. | [HS08TEST](https://www.codechef.com/problems/HS08TEST) |[ATM](https://github.com/Sahiljawale/CodeChef/blob/main/Python/ATM.py) | -|2. | [NOFIX](https://www.codechef.com/FEB222C/problems/NOFIX) |[Avoid Fix Point](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Avoid%20Fix%20Point.py) | -|3. | [TRAVELFAST](https://www.codechef.com/problems/TRAVELFAST) | [Car or Bus](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Car%20or%20Bus.py) | -|4. | [LOSTSEQ](https://www.codechef.com/START26B/problems/LOSTSEQ) |[Careless Chef](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Careless%20Chef.py) | -|5. | codechef URL |[Cats and a Mouse](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Cats%20and%20a%20Mouse.py) | -|6. | [HELIUM3](https://www.codechef.com/problems/HELIUM3) |[Chef and NextGen](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Chef%20and%20NextGen.py) | -|7. | [CIELAB](https://www.codechef.com/problems/CIELAB) |[Ciel and A-B Problem](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Ciel%20and%20A-B%20Problem.py) | -|8. | [Compare the Triplets](https://www.hackerrank.com/challenges/compare-the-triplets/problem) |[Compare the Triplets](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Compare%20the%20Triplets.py) | -|9. | [NOTEBOOK](https://www.codechef.com/submit/NOTEBOOK) |[Count the Notebook](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Count%20The%20Notebook.py) | -|10. | [DIV03](https://www.codechef.com/problems/DIV03) |[Daanish and Problems](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Daanish%20and%20Problems.py) | -|11. | codechef URL |[Day of the Programmer](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Day%20of%20the%20Programmer.py) | -|12. | [Diagonal Difference](https://www.hackerrank.com/challenges/diagonal-difference) |[Diagonal Difference](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Diagonal%20Difference.py) | -|13. | codechef URL |[Enormous Input Test](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Enormous%20Input%20Test.py) | -|14. | codechef URL |[GCD and LCM](https://github.com/Sahiljawale/CodeChef/blob/main/Python/GCD%20and%20LCM.py) | -|15. | [Gross Salary](https://www.codechef.com/problems/FLOW011) |[Gross Salary](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Gross%20Salary.py) | -|16. | codechef URL |[Hostel Room](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Hostel%20Room.py) | -|17. | codechef URL |[How Many Digits](https://github.com/Sahiljawale/CodeChef/blob/main/Python/How%20Many%20Digits.py) | -|18. | codechef URL |[Left Rotation](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Left%20Rotation.py) | -|19. | codechef URL |[List Comprehensions](https://github.com/Sahiljawale/CodeChef/blob/main/Python/List%20Comprehensions.py) | -|20. | codechef URL |[Mahasena](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Mahasena.py) | -|21. | codechef URL |[Maximize the Subsequence Sum](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Maximise%20the%20Subsequence%20Sum.py) | -|22. | codechef URL |[Maximum Weight Difference](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Maximum%20Weight%20Difference.py) | -|23. | codechef URL |[Migratory Birds](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Migratory%20Birds.py) | -|24. | codechef URL |[Most Frequency](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Most%20Frequency.py) | -|25. | codechef URL |[Possible Victory](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Possible%20Victory.py) | -|26. | codechef URL |[Racing Horses](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Racing%20Horses.py) | -|27. | codechef URL |[Reverse The Number](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Reverse%20The%20Number.py) | -|28. | codechef URL |[Smallest Numbers of Notes](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Smallest%20Numbers%20of%20Notes.py) | -|29. | codechef URL |[Total Expenses](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Total%20Expenses.py) | -|30. | codechef URL |[Turbo Sort](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Turbo%20Sort.py) | -|31. | codechef URL |[World Chess Championship](https://github.com/Sahiljawale/CodeChef/blob/main/Python/World%20Chess%20Championsh.py) | -|32. | codechef URL |[XOR Palindrome](https://github.com/Sahiljawale/CodeChef/blob/main/Python/XOR%20Palindrome.py) | -|33. | [CodeChef URL](https://www.codechef.com/LRNDSA02/problems/PSHOT) | [Penalty Shootout 2](https://github.com/Sahiljawale/CodeChef/blob/main/Python/Penalty%20Shootout%202.py) - -## Java - -| S.No. | Question | Solution | -|:------|:--------| :--------| -|1. | codechef URL |[Demo]([https://github.com/Sahiljawale/CodeChef/blob/main/Python/ATM.py](https://github.com/Sahiljawale/CodeChef/blob/main/Java/demo.java)) | -|2. | - - - -
diff --git a/TrappingWater.cpp b/TrappingWater.cpp deleted file mode 100644 index 994e826..0000000 --- a/TrappingWater.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -using namespace std; -//Naive Solution. -int MaxSum(int arr[] , int n) -{ - int res = 0 ; - for(int i = 0 ; i -#include -using namespace std; -int main() { - int test; - cin>>test; - while(test--){ - int n; - cin>>n; - int a[n]; - for(int i=0;i>a[i]; - } - int ans=0; - int count=INT_MAX; - int i=0,j=n-1; - int flag=0; - while(ia[j]){ - cout<<"-1"<count){ - cout<<"-1"< -using namespace std; -int main() -{ - int n, i; - cin >> n; - int a[n]; - for (i = 0; i < n; i++) - { - cin >> a[i]; - } - for(i=0;i -using namespace std; -int main() -{ - int n, i, store,s,k; - cin >> n; - int a[n], b[n],c[n]; - for (i = 0; i < n; i++) - { - cin >> a[i] >> b[i] >> c[i]; - } - for(i=0; i k){ - cout << k << "\n";} - else - cout << s << "\n"; - } - } - - return 0; -} diff --git a/codechef.c++ b/codechef.c++ deleted file mode 100644 index 872e9ce..0000000 --- a/codechef.c++ +++ /dev/null @@ -1,46 +0,0 @@ -//Problem -//It's dinner time. Ashish is very hungry and wants to eat something. He has XX rupees in his pocket. Since Ashish is very picky, he only likes to eat either PIZZA or BURGER. In addition, he prefers eating PIZZA over eating BURGER. The cost of a PIZZA is YY rupees while the cost of a BURGER is ZZ rupees. -// -//Ashish can eat at most one thing. Find out what will Ashish eat for his dinner. -// -//Input Format -//The first line will contain TT - the number of test cases. Then the test cases follow. -//The first and only line of each test case contains three integers XX, YY and ZZ - the money Ashish has, the cost of a PIZZA and the cost of a BURGER. -//Output Format -//For each test case, output what Ashish will eat. (PIZZA, BURGER or NOTHING). -// -//You may print each character of the string in uppercase or lowercase. (for example, the strings Pizza, pIzZa and piZZa will all be treated as identical). -// -//Constraints -//1 \leq T \leq 1001≤T≤100 -//1 \leq X, Y, Z \leq 1001≤X,Y,Z≤100 -//Input -//3 -//50 40 60 -//40 55 39 -//30 42 37 -//Output -//PIZZA -//BURGER -//NOTHING -//*************HUNGRY ASHISH************** -#include -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - while(t--){ - int x,y,z; - cin>>x>>y>>z; - if(y<=x) - cout<<"PIZZA"< -int main(){ - int i,j,n,count = 0,z; - scanf("%d%d", &n, &j); - for(i=0;i , <= , >=, != , ==| -| Bitwise Operator| & , ^ , \|, <<, >>, >>>| -| Logical Operator| && , `\|\|`, ! | -| Assignment Operator|= , += , -= , *= , /= , %= | -| Auto-increment and Auto-decrement Operators| ++ , -- | -| Ternary Operator| ? : | - -## Arrays - -Array is a collection of similar data which is stored in continuous memory addresses. - -```java -// one dimensional array -data-type[] array-name; - OR -data-type array-name[]; - -// two dimensional array -data-type[][] array-name; -``` -### Example -```java -String[] mobiles = {"iPhone", "Samsung", "OnePlus"}; -for (int i = 0; i < mobiles.length; i++) { - System.out.println(mobiles[i]); -} -mobiles[1] = "Oppo"; // change an array element - - -``` -## Conditional Statements - -### 1. If - -```java -if(conditional-expression) -{ - //code -} -``` -### 2. If-else - -```java -if(conditional-expression) -{ - //code -} else { - //code -} -``` -### 3. If-else-if ladder - -```java -if(conditional-expression-1) -{ - //code -} else if(conditional-expression-2) { - //code -} else if(conditional-expression-3) { - //code -} -.... -else { - //code -} -``` -### 4. Nested-If - -```java -if(conditional-expression-1) { - //code - if(conditional-expression-2) { - //code - if(conditional-expression-3) { - //code - } - } -} -``` -### 5. Switch -```java -switch(conditional-expression){ -case value1: - //code - break; //optional -case value2: - //code - break; //optional -... - -default: - //code to be executed when all the above cases are not matched; -} -``` -## Loops - -### 1. For -```java -for(Initialization; Condition; Increment/decrement){ -//code -} -``` - -### 2. While -```java -while(condition){ -//code -} -``` -### 3. Do-While -```java -do{ -//code -}while(condition); -``` -## Collections -|Collection|Description| -|-----|-----| -|Set| Set is a collection of elements which can not contain duplicate values. Set is implemented in HashSets, LinkedHashSets, TreeSet etc| -|List| List is a ordered collection of elements which can have duplicates. Lists are classified into ArrayList, LinkedList, Vectors| -|Queue| FIFO approach, while instantiating Queue interface you can either choose LinkedList or PriorityQueue.| -|Deque| Deque(Double Ended Queue) is used to add or remove elements from both the ends of the Queue(both head and tail)| -|Map| Map contains key-values pairs which don't have any duplicates. Map is implemented in HashMap, TreeMap etc.| - -## ArrayList - -The ArrayList class is a resizable array, which can be found in the java.util package. - -### Example - -```java - - import java.util.ArrayList; - -public class Main { - public static void main(String[] args) { - ArrayList cars = new ArrayList(); - cars.add("Volvo"); - cars.add("BMW"); - cars.add("Ford"); - cars.add("Mazda"); - System.out.println(cars); - } -} - -``` - -## HashSet - -A HashSet is a collection of items where every item is unique, and it is found in the java.util package: - - ### Example - - ```java - - import java.util.HashSet; - -public class Main { - public static void main(String[] args) { - HashSet cars = new HashSet(); - cars.add("Volvo"); - cars.add("BMW"); - cars.add("Ford"); - cars.add("BMW"); - cars.add("Mazda"); - System.out.println(cars); - } -} - - ``` - - ## HashMap - - A HashMap however, store items in "key/value" pairs, and you can access them by an index of another type (e.g. a String). - - ```java - - import java.util.HashMap; - -public class Main { - public static void main(String[] args) { - // Create a HashMap object called capitalCities - HashMap capitalCities = new HashMap(); - - // Add keys and values (Country, City) - capitalCities.put("England", "London"); - capitalCities.put("Germany", "Berlin"); - capitalCities.put("Norway", "Oslo"); - capitalCities.put("USA", "Washington DC"); - System.out.println(capitalCities); - } -} - - ``` - -## String Methods -| Method| Description| Example| -|----|----|----| -|char charAt(int index)|returns char value at the specific index| str.charAt(0) //prints o| -|int compareTo(String str)| to compare two strings lexicographically | Str1.compareTo(Str2) //returns 0 if str1 and str2 are equal| -|int length()|returns string length| str.length()| -|static String format(String format, Object... args)|returns a formatted string.| String.format("String is %s",str); | -|String substring(int beginIndex, int endIndex)| to return substring from given begin index to end index.| str.substring(0,3) //prints one| -|String substring(int beginIndex)| to return substring from given begin index| str.substring(3) //prints compiler| -|boolean contains(CharSequence s)|returns true or false after matching the sequence given in the string| str.contains("compiler") // returns true| -|static String join(CharSequence delimiter, CharSequence... elements)|returns a joined string.| String.join("..","Hello","Happy", "Learning"); //returns Hello..Happy..Learning| -|boolean equals(Object another)|checks the equality of string with another and returns true if they are equal.| str1.equals(str2);| -|boolean isEmpty()|to check if the given string is empty.| str.isEmpty() // returns false| -|String concat(String str)|concatenates the provided string with the another string.| str.concat(" is used to compile code online")| -|String replace(char old, char new)|replaces all occurrences of the specified char value with new char value.|str.replace('r','t');| -|String replace(CharSequence old, CharSequence new)|replaces all occurrences of the specific CharSequence with new one.|str.replace('one','Online');| -|static String equalsIgnoreCase(String another)|compares another string with out considering case.| str1.equalsIgnoreCase(str2)| -|String[] split(String regex, int limit)|returns a split string matching regex and limit. here limit is optional| str.split("\\s")//splits string based on whitespaces| -|int indexOf(String substring, int fromIndex)|returns the specified substring index starting with given index. here index is optional| str.indexOf("compiler",2);| -|String toLowerCase()|returns a string in lowercase.|str.toLowercase();| -|String toUpperCase()|returns a string in uppercase.|str.toUpperCase();| -|String trim()|removes beginning and trailing spaces of a given string.|str.trim();| -|boolean endsWith(String chars)|Checks whether a string ends with the specified character(s).|str.endsWith("Hel")| - -## OOPS - -### 1. Class - -Class is the blueprint of an object and `class` keyword is required to create a class. - -```java -class class_name { - fields; - methods; -} -``` - -### 2. Object - -Object is a basic unit in OOP, and is an instance of the class. - -```java -class_name obj_name; -``` -### 3. Abstraction - -Data abstraction is a technique which provides only the required data to be visible or accessible to outside world. -`abstract` keyword is used for classes and methods. - - -```java - -abstract class Mobiles { // abstract class - public abstract void features(); // abstract method - public void method-name() { - //code - } -} -``` -### 4. Encapsulation - -Encapsulation is a mechanism to protect private hidden from other users. It wraps the data and methods as a single bundle. `private` is the keyword used to declare the variables or methods as private. You can make public `set` and `get` methods to access private variables. - -### 5. Polymorphism - -Polymorphism gives the meaning many forms, usually it occurs when multiple classes are present and have been inherited. - -```java -// compile time polymorphism -class Example { - static int exampleFunction(int a, int b) { - return a+b; - } - static double exampleFunction(double a, double b) { - return a+b; - } -} - -class Main { - public static void main(String[] args) { - System.out.println(Example.exampleFunction(2, 3)); - System.out.println(Example.exampleFunction(2.82, 3.2225)); - } -} -``` - -```java -// run time polymorphism -class Parent { - public void print() { - System.out.println("Parent"); - } -} - -class Child extends Parent { - public void print() { - System.out.println("Child"); - } -} - -class Main { - public static void main(String[] args) { - - Parent p = new Parent(); - p.print(); - - p = new Child(); - p.print(); - } -} -``` - -### 6. Inheritance -Inheritance in Java is a mechanism in which one object `acquires all the properties and behaviors of a parent object`. -The `extends` keyword indicates that you are making a new class that derives from an existing class. -```java -class ChildClass extends ParentClass { - //code -} -``` - -### Constructor - -Constructor is a special type of method. -Every class has atleast one constructor. -Without Constructor, object from the class cannot be created, that's why constructor is mandatory in every class. -Name of the constructor should be the name of the class. -Constructor has no return type. - -```java -public class AA { //beg of class - public void AA() { //default constructor - //code - } - } - ``` diff --git a/laptop_recommendations.cpp b/laptop_recommendations.cpp deleted file mode 100644 index e30b336..0000000 --- a/laptop_recommendations.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -using namespace std; - -int main() -{ - - int t; - cin >> t; - int ans[t]; - - for (int i = 0; i < t; i++) - { - - int n, c = 0; - cin >> n; - int arr[n]; - for (int i = 0; i < n; i++) - cin >> arr[i]; - for (int i = 0; i < n; i++) - { - for(int i = 0; j=` and `>` -- Bit operators: `&`, `|`, `^` (bitwise exclusive or) and `~` (bitwise negation) -- Arithmetic operators: `+`, `-`, unary `-`, unary `+`, `*`, `/`, `%`, `**` (exponentiation), `<<` (left shift) and `>>` (right shift) - -### Address - -`address`: Holds an Ethereum address (20 byte value). -`address payable` : Same as address, but includes additional methods `transfer` and `send` - -Operators: - -- Comparisons: `<=`, `<`, `==`, `!=`, `>=` and `>` - -Methods: - -#### balance - -- `
.balance (uint256)`: balance of the Address in Wei - -#### transfer and send - -- `
.transfer(uint256 amount)`: send given amount of Wei to Address, throws on failure -- `
.send(uint256 amount) returns (bool)`: send given amount of Wei to Address, returns false on failure - -#### call -- `
.call(...) returns (bool)`: issue low-level CALL, returns false on failure - -#### delegatecall - -- `
.delegatecall(...) returns (bool)`: issue low-level DELEGATECALL, returns false on failure. - -#### callcode -- `
.callcode(...) returns (bool)`: issue low-level CALLCODE, returns false on failure - -## Control Structures - -Most of the control structures from JavaScript are available in Solidity except for `switch` and `goto`. - -- `if` `else` -- `while` -- `do` -- `for` -- `break` -- `continue` -- `return` -- `? :` - -### Flow Control - -`if (condition) { ... };` -`if (condition) { ... } else { ... };` -`for (declaration; condition; expression) { ... };` - -`while (condition) { ... };` -`do { ... } while (condition);` -`condition ? expression : expression;` - -> continue, break and return can be used to influence flow. - -### Array - -Arrays can be dynamic or have a fixed size. - -```solidity -uint[] dynamicSizeArray; - -uint[7] fixedSizeArray; -``` - -`myArray[3]; - get element` -`myArray[3] = 8; - set element` -`uint[] memory myArray = new uint[](5);` -> memory array with size determined at runtime. Memory arrays can't have dynamic size - -### Fixed byte arrays - -`bytes1(byte)`, `bytes2`, `bytes3`, ..., `bytes32`. - -Operators: - -Comparisons: `<=`, `<`, `==`, `!=`, `>=`, `>` (evaluate to bool) -Bit operators: `&`, `|`, `^` (bitwise exclusive or), `~` (bitwise negation), `<<` (left shift), `>>` (right shift) -Index access: If x is of type bytesI, then x[k] for 0 <= k < I returns the k th byte (read-only). - -Members - -- `.length` : read-only - -### Dynamic byte arrays - -`bytes`: Dynamically-sized `byte` array. It is similar to `byte[]`, but it is packed tightly in calldata. Not a value-type! - -`string`: Dynamically-sized UTF-8-encoded string. It is equal to `bytes` but does not allow length or index access. Not a value-type! - -### Enum - -Enum works just like in every other language. - -```solidity -enum ActionChoices { - GoLeft, - GoRight, - GoStraight, - SitStill -} - -ActionChoices choice = ActionChoices.GoStraight; -``` - -### Struct - -New types can be declared using struct. - -```solidity -struct Funder { - address addr; - uint amount; -} - -Funder funders; -``` - -### Mapping - -Declared as `mapping(_KeyType => _ValueType)` - -Mappings can be seen as **hash tables** which are virtually initialized such that every possible key exists and is mapped to a value. - -**key** can be almost any type except for a mapping, a dynamically sized array, a contract, an enum, or a struct. **value** can actually be any type, including mappings. - -> All possible mapping keys always exists and have a default byte value of all zeroes. Can't be iterated, checked for length, retrieve which keys were set etc. Also can't be created in memory. - ---- - -## Functions - -### Structure - -`function () {internal|external|public|private} [pure|constant|view|payable] [returns ()]` - -### Access modifiers - -- ```public``` - Accessible from this contract, inherited contracts and externally -- ```private``` - Accessible only from this contract -- ```internal``` - Accessible only from this contract and contracts inheriting from it -- ```external``` - Cannot be accessed internally, only externally. Recommended to reduce gas. Access internally with `this.f`. - -### Parameters - -#### Input parameters - -Parameters are declared just like variables and are `memory` variables. - -```solidity -function f(uint _a, uint _b) {} -``` - -#### Output parameters - -Output parameters are declared after the `returns` keyword - -```solidity -function f(uint _a, uint _b) returns (uint _sum) { - _sum = _a + _b; -} -``` - -Output can also be specified using `return` statement. In that case, we can omit parameter name `returns (uint)`. - -Multiple return types are possible with `return (v0, v1, ..., vn)`. - - -### Constructor - -Function that is executed during contract deployment. Defined using the `constructor` keyword. - -```solidity -contract C { - address owner; - uint status; - constructor(uint _status) { - owner = msg.sender; - status = _status; - } -} -``` - -### Function Calls - -#### Internal Function Calls - -Functions of the current contract can be called directly (internally - via jumps) and also recursively - -```solidity -contract C { - function funA() returns (uint) { - return 5; - } - - function FunB(uint _a) returns (uint ret) { - return funA() + _a; - } -} -``` - -#### External Function Calls - -`this.g(8);` and `c.g(2);` (where c is a contract instance) are also valid function calls, but, the function will be called “externally”, via a message call. - -> `.gas()` and `.value()` can also be used with external function calls. - -#### Named Calls - -Function call arguments can also be given by name in any order as below. - -```solidity -function f(uint a, uint b) { } - -function g() { - f({b: 1, a: 2}); -} -``` - -#### Unnamed function parameters - -Parameters will be present on the stack, but are not accessible. - -```solidity -function f(uint a, uint) returns (uint) { - return a; -} -``` - -### Function Modifier - -Modifiers can automatically check a condition prior to executing the function. - -```solidity -modifier onlyOwner { - require(msg.sender == owner); - _; -} - -function close() onlyOwner { - selfdestruct(owner); -} -``` - -### Function type - -Pass function as a parameter to another function. Similar to `callbacks` and `delegates` - -```solidity -pragma solidity ^0.4.18; - -contract Oracle { - struct Request { - bytes data; - function(bytes memory) external callback; - } - Request[] requests; - event NewRequest(uint); - function query(bytes data, function(bytes memory) external callback) { - requests.push(Request(data, callback)); - NewRequest(requests.length - 1); - } - function reply(uint requestID, bytes response) { - // Here goes the check that the reply comes from a trusted source - requests[requestID].callback(response); - } -} - -contract OracleUser { - Oracle constant oracle = Oracle(0x1234567); // known contract - function buySomething() { - oracle.query("USD", this.oracleResponse); - } - function oracleResponse(bytes response) { - require(msg.sender == address(oracle)); - } -} -``` - -### Pure Functions - -Functions can be declared `pure` in which case they promise not to read from or modify the state. - -```solidity -function f(uint a) pure returns (uint) { - return a * 42; -} -``` - -### Payable Functions - -Functions that receive `Ether` are marked as `payable` function. - -### Fallback Function - -A contract can have exactly one **unnamed function**. This function cannot have arguments and cannot return anything. It is executed on a call to the contract if none of the other functions match the given function identifier (or if no data was supplied at all). - -```solidity -function() { - // Do something -} -``` - - -### Mathematical and Cryptographic Functions - -- `addmod(uint x, uint y, uint k) returns (uint)`: - compute (x + y) % k where the addition is performed with arbitrary precision and does not wrap around at 2**256. -- `mulmod(uint x, uint y, uint k) returns (uint)`: - compute (x * y) % k where the multiplication is performed with arbitrary precision and does not wrap around at 2**256. -- `sha3(...) returns (bytes32)`: - alias to keccak256 -- `ripemd160(...) returns (bytes20)`: - compute RIPEMD-160 hash of the (tightly packed) arguments -- `keccak256(...) returns (bytes32)`: - compute the Ethereum-SHA-3 (Keccak-256) hash of the (tightly packed) arguments -- `sha256(...) returns (bytes32)`: - compute the SHA-256 hash of the (tightly packed) arguments - ---- - -## Interface - -`Interfaces` are similar to abstract contracts, but they have restrictions: - -- Cannot have any functions implemented. -- Cannot inherit other contracts or interfaces. -- Cannot define constructor. -- Cannot define variables. -- Cannot define structs. -- Cannot define enums. - -> Interfaces are like abstract contracts which other contracts can inherit. Inheriting contract has to implement all interface methods. Interfaces can't contain anything else than function signatures. - -```solidity -pragma solidity ^0.4.11; - -interface Token { - function transfer(address recipient, uint amount); -} -``` - ---- - -## Contracts - -### Creating contracts using `new` - -Contracts can be created from another contract using `new` keyword. The source of the contract has to be known in advance. - -```solidity -contract A { - function add(uint _a, uint _b) returns (uint) { - return _a + _b; - } -} - -contract C { - address a; - function f(uint _a) { - a = new A(); - } -} -``` - -### Contract Inheritance - -Solidity supports multiple inheritance and polymorphism. - -```solidity -contract owned { - function owned() { owner = msg.sender; } - address owner; -} - -contract mortal is owned { - function kill() { - if (msg.sender == owner) selfdestruct(owner); - } -} - -contract final is mortal { - function kill() { - super.kill(); // Calls kill() of mortal. - } -} -``` - -##### Example - -`Memo memo = new Memo("my precious memo");` - create new contract -`Memo memo = Memo(existingMemoAddress);` - intialize already existing contract -`this;` - current contract -`address(this);` - converts contract to address -`selfdestruct(ownerAddress);` - destroys contract and sends it's funds to address. Must be called from contract. - -#### Constructor of base class - -```solidity -contract A { - uint a; - constructor(uint _a) { a = _a; } -} - -contract B is A(1) { - constructor(uint _b) A(_b) { - } -} -``` - -### Abstract Contracts - -Contracts that contain implemented and non-implemented functions. Such contracts cannot be compiled, but they can be used as base contracts. - -```solidity -pragma solidity ^0.4.0; - -contract A { - function C() returns (bytes32); -} - -contract B is A { - function C() returns (bytes32) { return "c"; } -} -``` ---- - -## Deprecations - -`constant` - function modifier -`year` - time literal suffix -`throw` - alias to revert -`block.blockhash(block_number);` - replaced by global blockhash(block_number); -`msg.gas` - replaced by global gasleft(); -`suicide` - alias to selfdestruct(address) -`keccak256(a, b)` - deprecated in favor ofkeccak256(abi.encodePacked(a, b)) - - - -## Events - -Events allow the convenient usage of the EVM logging facilities, which in turn can be used to “call” JavaScript callbacks in the user interface of a dapp, which listen for these events. - -Up to three parameters can receive the attribute indexed, which will cause the respective arguments to be searched for. - -> All non-indexed arguments will be stored in the data part of the log. - -```solidity -pragma solidity ^0.4.0; - -contract ClientReceipt { - event Deposit( - address indexed _from, - bytes32 indexed _id, - uint _value - ); - - function deposit(bytes32 _id) payable { - emit Deposit(msg.sender, _id, msg.value); - } -} -``` - - -## Library - -Libraries are similar to contracts, but they are deployed only once at a specific address, and their code is used with [`delegatecall`](#delegatecall) (`callcode`). - -```solidity -library arithmatic { - function add(uint _a, uint _b) returns (uint) { - return _a + _b; - } -} - -contract C { - uint sum; - - function f() { - sum = arithmatic.add(2, 3); - } -} -``` - -## Error Handling - -- `assert(bool condition)`: throws if the condition is not met - to be used for internal errors. -- `require(bool condition)`: throws if the condition is not met - to be used for errors in inputs or external components. -- `revert()`: abort execution and revert state changes - -```solidity - function sendHalf(address addr) payable returns (uint balance) { - require(msg.value % 2 == 0); // Only allow even numbers - uint balanceBeforeTransfer = this.balance; - addr.transfer(msg.value / 2); - assert(this.balance == balanceBeforeTransfer - msg.value / 2); - return this.balance; -} -``` - ---- - -## Variables - -### Transaction variables - -- `msg.data (bytes)`: complete calldata -- `msg.gas (uint)`: remaining gas -- `msg.sender (address)`: sender of the message (current call) -- `msg.sig (bytes4)`: first four bytes of the calldata (i.e. function identifier) -- `msg.value (uint)`: number of wei sent with the message -- `tx.gasprice (uint)`: gas price of the transaction -- `tx.origin (address)`: sender of the transaction (full call chain) - - -### Block variables - -- `block.blockhash(uint blockNumber) returns (bytes32)`: hash of the given block - only works for the 256 most recent blocks excluding current -- `block.coinbase (address)`: current block miner’s address -- `block.difficulty (uint)`: current block difficulty -- `block.gaslimit (uint)`: current block gaslimit -- `block.number (uint)`: current block number -- `block.timestamp (uint)`: current block timestamp as seconds since unix epoch -- `now (uint)`: current block timestamp (alias for `block.timestamp`) - - -Here is an image cheatsheet for quick recall. [Image](https://intellipaat.com/mediaFiles/2019/03/Solidity-Cheat-Sheet.jpg) From 6305518917bfcfef26a5f246a62664afc928c100 Mon Sep 17 00:00:00 2001 From: TeJa <102944401+Teju-1212@users.noreply.github.com> Date: Fri, 21 Oct 2022 19:14:58 +0530 Subject: [PATCH 2/2] Create README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..7e4eba3 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# CodeChef +This repository contains solutions for problems on codechef.com