├── LANGUAGE PROFICIENCY ├── C++ │ ├── Classes │ │ ├── AbstractClassesPolymorphism.cpp │ │ ├── BoxIt.cpp │ │ ├── Class.cpp │ │ ├── ClassesAndObjects.cpp │ │ ├── ExceptionalServer.cpp │ │ ├── InheritedCode.cpp │ │ ├── Structs.cpp │ │ └── VirtualFunctions.cpp │ ├── Inheritance │ │ ├── AccessingInheritedFunctions.cpp │ │ ├── InheritanceIntroduction.cpp │ │ ├── MagicSpells.cpp │ │ ├── MultiLevelInheritance.cpp │ │ └── RectangleArea.cpp │ ├── Introduction │ │ ├── ArraysIntroduction.cpp │ │ ├── BasicDataTypes.cpp │ │ ├── ConditionalStatements.cpp │ │ ├── ForLoop.cpp │ │ ├── Functions.cpp │ │ ├── InputAndOutput.cpp │ │ ├── Pointer.cpp │ │ ├── SayHelloWorldWithCPlusPlus.cpp │ │ └── VariableSizedArrays.cpp │ ├── Other Concepts │ │ ├── AttendingWorkshops.cpp │ │ ├── ClassTemplateSpecialization.cpp │ │ ├── ClassTemplates.cpp │ │ ├── OperatorOverloading.cpp │ │ ├── OverloadOperators.cpp │ │ └── PreprocessorSolution.cpp │ ├── STL │ │ ├── DequeStl.cpp │ │ ├── LowerBoundStl.cpp │ │ ├── MapsStl.cpp │ │ ├── PrintPretty.cpp │ │ ├── SetsStl.cpp │ │ ├── VectorErase.cpp │ │ └── VectorSort.cpp │ └── Strings │ │ ├── AttributeParser.cpp │ │ ├── StringStream.cpp │ │ └── Strings.cpp ├── C │ ├── Arrays and Strings │ │ ├── 1DArraysInC.c │ │ ├── ArrayReversal.c │ │ ├── DigitFrequency.c │ │ ├── DynamicArrayInC.c │ │ └── PrintingTokens.c │ ├── Conditionals and Loops │ │ ├── BitwiseOperators.c │ │ ├── ConditionalStatementsInC.c │ │ ├── ForLoopInC.c │ │ ├── PrintingPatternsUsingLoops.c │ │ └── SumOfDigitsOfAFiveDigitNumber.c │ ├── Functions │ │ ├── CalculateTheNthTerm.c │ │ ├── PermutationsOfStrings.c │ │ ├── QueryingTheDocument.c │ │ ├── SortingArrayOfStrings.c │ │ ├── StudentsMarksSum.c │ │ └── VariadicFunctionsInC.c │ ├── Introduction │ │ ├── FunctionsInC.c │ │ ├── HelloWorld.c │ │ ├── PlayingWithCharacters.c │ │ ├── PointersInC.c │ │ └── SumAndDifferenceOfTwoNumbers.c │ └── Structs and Enums │ │ ├── BoxesThroughATunnel.c │ │ ├── PostTransition.c │ │ ├── SmallTrianglesLargeTriangles.cpp │ │ └── StructuringTheDocument.c ├── Java │ ├── BigNumber │ │ ├── JavaBigDecimal.java │ │ ├── JavaBigInteger.java │ │ └── JavaPrimalityTest.java │ ├── Data Structures │ │ ├── Java1DArray.java │ │ ├── Java2DArray.java │ │ ├── JavaArraylist.java │ │ ├── JavaList.java │ │ └── JavaSubarray.java │ ├── Introduction │ │ ├── JavaCurrencyFormatter.java │ │ ├── JavaDatatypes.java │ │ ├── JavaDateAndTime.java │ │ ├── JavaEndOfFile.java │ │ ├── JavaIfElse.java │ │ ├── JavaIntToString.java │ │ ├── JavaLoops1.java │ │ ├── JavaLoops2.java │ │ ├── JavaOutputFormatting.java │ │ ├── JavaStaticInitializerBlock.java │ │ ├── JavaStdInAndStdOut1.java │ │ └── WelcomeToJava.java │ └── Strings │ │ ├── JavaAnagrams.java │ │ ├── JavaRegex.java │ │ ├── JavaRegex2DuplicateWords.java │ │ ├── JavaStringTokens.java │ │ ├── JavaStringsIntroduction.java │ │ ├── JavaSubstring.java │ │ ├── JavaSubstringComparisons.java │ │ ├── PatternSyntaxChecker.java │ │ ├── TagContentExtractor.java │ │ └── ValidUsernameRegularExpression.java ├── Python │ ├── .idea │ │ ├── Python.iml │ │ ├── encodings.xml │ │ ├── libraries │ │ │ └── R_User_Library.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── vcs.xml │ │ └── workspace.xml │ ├── Basic Data Types │ │ ├── FindTheRunnerUpScore.py │ │ ├── FindingThePercentage.py │ │ ├── ListComprehensions.py │ │ ├── Lists.py │ │ ├── NestedLists.py │ │ └── Tuples.py │ ├── Introduction │ │ ├── ArithmeticOperators.py │ │ ├── Loops.py │ │ ├── PrintFunction.py │ │ ├── PythonDivision.py │ │ ├── PythonIfElse.py │ │ ├── SayHelloWorldWithPython.py │ │ └── WriteAFunction.py │ ├── Itertools │ │ ├── compress_the_string.py │ │ ├── iterables_and_iterators.py │ │ ├── itertools_combinations.py │ │ ├── itertools_combinations_with_replacement.py │ │ ├── itertools_permutations.py │ │ ├── itertools_product.py │ │ └── maximize_it.py │ ├── Math │ │ ├── FindAngleMBC.py │ │ ├── IntegersComeInAllSizes.py │ │ ├── ModDivmod.py │ │ ├── PolarCoordinates.py │ │ ├── PowerModPower.py │ │ ├── TriangleQuest.py │ │ └── TriangleQuest2.py │ ├── Sets │ │ ├── CheckStrictSuperset.py │ │ ├── CheckSubset.py │ │ ├── IntroductionToSets.py │ │ ├── NoIdea.py │ │ ├── SetAdd.py │ │ ├── SetDifference.py │ │ ├── SetDiscardRemovePop.py │ │ ├── SetIntersection.py │ │ ├── SetMutations.py │ │ ├── SetSymmetricDifference.py │ │ ├── SetUnion.py │ │ ├── SymmetricDifference.py │ │ └── TheCaptiansRoom.py │ └── Strings │ │ ├── AlphabetRangoli.py │ │ ├── Capitalize.py │ │ ├── DesignerDoorMat.py │ │ ├── FindAString.py │ │ ├── MergeTheTools.py │ │ ├── Mutations.py │ │ ├── StringFormatting.py │ │ ├── StringSplitAndJoin.py │ │ ├── StringValidators.py │ │ ├── SwapCase.py │ │ ├── TextAlignment.py │ │ ├── TextWrap.py │ │ ├── TheMinionGame.py │ │ └── WhatsYourName.py └── Shell │ ├── Arrays in Bash │ ├── ConcatenateAnArrayWithItself.sh │ ├── CountTheNumberOfElementsInAnArray.sh │ ├── DisplayAnElementOfAnArray.sh │ ├── FilterAnArrayWithPatterns.sh │ ├── LonelyIntegerBash.sh │ ├── ReadInAnArray.sh │ ├── RemoveTheFirstCapitalLetterFromEachElement.sh │ └── SliceAnArray.sh │ ├── Bash │ ├── APersonalizedEcho.sh │ ├── ArithmeticOperations.sh │ ├── ComparingNumbers.sh │ ├── ComputeTheAverage.sh │ ├── FunctionsAndFractalsRecursiveTreesBash.sh │ ├── GettingStartedWithConditionals.sh │ ├── LetsEcho.sh │ ├── LoopingAndSkipping.sh │ ├── LoopingWithNumbers.sh │ ├── MoreOnConditionals.sh │ └── TheWorldOfNumbers.sh │ ├── Grep Sed Awk │ ├── Awk1.sh │ ├── Awk2.sh │ ├── Awk3.sh │ ├── Awk4.sh │ ├── Grep#1.sh │ ├── Grep#2.sh │ ├── Grep#3.sh │ ├── GrepA.sh │ ├── GrepB.sh │ ├── SedCommand#1.sh │ ├── SedCommand#2.sh │ ├── SedCommand#3.sh │ ├── SedCommand#4.sh │ └── SedCommand#5.sh │ └── Text Processing │ ├── Cut#1.sh │ ├── Cut#5.sh │ ├── Cut#6.sh │ ├── Cut#7.sh │ ├── Cut#8.sh │ ├── Cut#9.sh │ ├── HeadOfATextFile#1.sh │ ├── HeadOfATextFile#2.sh │ ├── MiddleOfATextFile.sh │ ├── Paste1.sh │ ├── Paste2.sh │ ├── Paste3.sh │ ├── Paste4.sh │ ├── SortCommand#1.sh │ ├── SortCommand#2.sh │ ├── SortCommand#3.sh │ ├── SortCommand#4.sh │ ├── SortCommand#5.sh │ ├── SortCommand#6.sh │ ├── SortCommand#7.sh │ ├── TailOfATextFile#1.sh │ ├── TailOfATextFile#2.sh │ ├── TrCommand#1.sh │ ├── TrCommand#2.sh │ ├── TrCommand#3.sh │ ├── UniqCommand#1.sh │ ├── UniqCommand#2.sh │ ├── UniqCommand#3.sh │ ├── UniqCommand#4.sh │ ├── cut#2.sh │ ├── cut#3.sh │ └── cut#4.sh ├── README.md ├── TUTORIALS └── Javascript │ ├── arithmetic_operators.js │ ├── arrays.js │ ├── arrow_functions.js │ ├── binaryCalculator.js │ ├── bitwise_operators.js │ ├── button.js │ ├── buttonsGrid.js │ ├── classes.js │ ├── count_objects.js │ ├── create_a_rectangle_object.js │ ├── data_types.js │ ├── functions.js │ ├── hello_world.js │ ├── if_else.js │ ├── inheritance.js │ ├── javascript_dates.js │ ├── let_and_const.js │ ├── loops.js │ ├── regular_expressions_1.js │ ├── regular_expressions_2.js │ ├── regular_expressions_3.js │ ├── switch.js │ ├── template_literals.js │ ├── throw.js │ └── try_catch_and_finally.js └── images └── HackerRankLogo.svg /LANGUAGE PROFICIENCY/C++/Classes/AbstractClassesPolymorphism.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | struct Node{ 11 | Node* next; 12 | Node* prev; 13 | int value; 14 | int key; 15 | Node(Node* p, Node* n, int k, int val):prev(p),next(n),key(k),value(val){}; 16 | Node(int k, int val):prev(NULL),next(NULL),key(k),value(val){}; 17 | }; 18 | 19 | class Cache{ 20 | 21 | protected: 22 | map mp; //map the key to the node in the linked list 23 | int cp; //capacity 24 | Node* tail; // double linked list tail pointer 25 | Node* head; // double linked list head pointer 26 | virtual void set(int, int) = 0; //set function 27 | virtual int get(int) = 0; //get function 28 | 29 | }; 30 | class LRUCache : public Cache { 31 | public: 32 | LRUCache(int c) { cp = c; } 33 | 34 | void set(int k, int v) { 35 | Node *N; 36 | 37 | if (mp.empty()) // No nodes 38 | { 39 | N = new Node(k, v); 40 | tail = head = N; 41 | mp[k] = N; 42 | 43 | return; 44 | } 45 | 46 | auto it = mp.find(k); 47 | 48 | if (it != mp.end()) // In hash table 49 | { 50 | it->second->value = v; // update value 51 | 52 | if (head == it->second) // head? 53 | return; 54 | 55 | it->second->prev->next = it->second->next; 56 | 57 | if (tail == it->second) // tail? 58 | tail = tail->prev; 59 | else // in between? 60 | it->second->next->prev = it->second->prev; 61 | 62 | it->second->next = head; 63 | it->second->prev = NULL; 64 | head->prev = it->second; 65 | head = it->second; 66 | } else // No in hash table 67 | { 68 | N = new Node(head->prev, head, k, v); // new node 69 | head->prev = N; 70 | head = N; 71 | mp[k] = N; 72 | 73 | if (mp.size() > cp) // capacity? 74 | { 75 | tail = tail->prev; 76 | mp.erase(tail->next->key); 77 | delete tail->next; 78 | tail->next = NULL; 79 | } 80 | } 81 | } 82 | 83 | int get(int k) { 84 | auto it = mp.find(k); 85 | if (it != mp.end()) 86 | return it->second->value; 87 | 88 | return -1; 89 | } 90 | }; 91 | int main() { 92 | int n, capacity,i; 93 | cin >> n >> capacity; 94 | LRUCache l(capacity); 95 | for(i=0;i> command; 98 | if(command == "get") { 99 | int key; 100 | cin >> key; 101 | cout << l.get(key) << endl; 102 | } 103 | else if(command == "set") { 104 | int key, value; 105 | cin >> key >> value; 106 | l.set(key,value); 107 | } 108 | } 109 | return 0; 110 | } 111 | 112 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Classes/BoxIt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class Box { 6 | int l, b, h; 7 | 8 | public: 9 | Box(); 10 | Box(int,int,int); 11 | Box(Box&); 12 | int getLength(); 13 | int getBreadth (); 14 | int getHeight (); 15 | long long CalculateVolume(); 16 | 17 | bool operator<(Box& b); 18 | friend ostream& operator<<(ostream& out, Box& B); 19 | }; 20 | 21 | Box :: Box () { 22 | l = b = h = 0; 23 | } 24 | 25 | Box :: Box (int length, int breadth, int height) { 26 | l = length; 27 | b = breadth; 28 | h = height; 29 | } 30 | 31 | Box :: Box (Box &B) { 32 | l = B.l; 33 | b = B.b; 34 | h = B.h; 35 | } 36 | 37 | int Box :: getLength() { 38 | return l; 39 | } 40 | 41 | int Box :: getBreadth () { 42 | return b; 43 | } 44 | 45 | int Box :: getHeight () { 46 | return h; 47 | } 48 | 49 | long long Box :: CalculateVolume() { 50 | return (long long)l * b * h; 51 | } 52 | 53 | bool Box :: operator<(Box& B) { 54 | if (l < B.l) return true; 55 | else if(b < B.b && l == B.l) return true; 56 | else if(h < B.h && b == B.b && l == B.l) return true; 57 | else return false; 58 | } 59 | 60 | ostream& operator<<(ostream& out, Box& B) { 61 | out << B.l << ' ' << B.b << ' ' << B.h; 62 | return out; 63 | } 64 | 65 | 66 | void check2() 67 | { 68 | int n; 69 | cin>>n; 70 | Box temp; 71 | for(int i=0;i>type; 75 | if(type ==1) 76 | { 77 | cout<>l>>b>>h; 83 | Box NewBox(l,b,h); 84 | temp=NewBox; 85 | cout<>l>>b>>h; 91 | Box NewBox(l,b,h); 92 | if(NewBox 2 | #include 3 | using namespace std; 4 | 5 | class Student { 6 | int age; 7 | string first_name; 8 | string last_name; 9 | int standard; 10 | 11 | public: 12 | void set_age(int age); 13 | void set_first_name(string fname); 14 | void set_last_name(string lname); 15 | void set_standard(int standard); 16 | 17 | int get_age(); 18 | string get_first_name(); 19 | string get_last_name(); 20 | int get_standard(); 21 | 22 | string to_string(); 23 | 24 | }; 25 | 26 | void Student :: set_age(int a) { 27 | age = a; 28 | } 29 | 30 | void Student :: set_first_name(string fname) { 31 | first_name = fname; 32 | } 33 | 34 | void Student :: set_last_name(string lname) { 35 | last_name = lname; 36 | } 37 | 38 | void Student :: set_standard(int s) { 39 | standard = s; 40 | } 41 | 42 | int Student :: get_age() {return age;} 43 | string Student :: get_first_name() {return first_name;} 44 | string Student :: get_last_name() { return last_name;} 45 | int Student :: get_standard() {return standard;} 46 | 47 | string Student :: to_string() { 48 | char ch = ','; 49 | stringstream ss; 50 | ss << age << ch << first_name << ch << last_name << ch << standard; 51 | return ss.str(); 52 | } 53 | 54 | int main() { 55 | int age, standard; 56 | string first_name, last_name; 57 | 58 | cin >> age >> first_name >> last_name >> standard; 59 | 60 | Student st; 61 | st.set_age(age); 62 | st.set_standard(standard); 63 | st.set_first_name(first_name); 64 | st.set_last_name(last_name); 65 | 66 | cout << st.get_age() << "\n"; 67 | cout << st.get_last_name() << ", " << st.get_first_name() << "\n"; 68 | cout << st.get_standard() << "\n"; 69 | cout << "\n"; 70 | cout << st.to_string(); 71 | 72 | return 0; 73 | } 74 | 75 | 76 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Classes/ClassesAndObjects.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | class Student { 9 | int scores[5]; 10 | public: 11 | void input(){ 12 | for(int i = 0; i < 5; i++) { 13 | cin >> scores[i]; 14 | } 15 | } 16 | int calculateTotalScore(){ 17 | int sum = 0; 18 | for (int i = 0; i < 5; i++) { 19 | sum += scores[i]; 20 | } 21 | return sum; 22 | } 23 | }; 24 | int main() { 25 | int n; // number of students 26 | cin >> n; 27 | Student *s = new Student[n]; // an array of n students 28 | 29 | for(int i = 0; i < n; i++){ 30 | s[i].input(); 31 | } 32 | 33 | // calculate kristen's score 34 | int kristen_score = s[0].calculateTotalScore(); 35 | 36 | // determine how many students scored higher than kristen 37 | int count = 0; 38 | for(int i = 1; i < n; i++){ 39 | int total = s[i].calculateTotalScore(); 40 | if(total > kristen_score){ 41 | count++; 42 | } 43 | } 44 | 45 | // print result 46 | cout << count; 47 | 48 | return 0; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Classes/ExceptionalServer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | class Server { 10 | private: 11 | static int load; 12 | public: 13 | static int compute(long long A, long long B) { 14 | load += 1; 15 | if(A < 0) { 16 | throw std::invalid_argument("A is negative"); 17 | } 18 | vector v(A, 0); 19 | int real = -1, cmplx = sqrt(-1); 20 | if(B == 0) throw 0; 21 | real = (A/B)*real; 22 | int ans = v.at(B); 23 | return real + A - B*ans; 24 | } 25 | static int getLoad() { 26 | return load; 27 | } 28 | }; 29 | int Server::load = 0; 30 | 31 | int main() { 32 | int T; cin >> T; 33 | while(T--) { 34 | long long A, B; 35 | cin >> A >> B; 36 | Server s; 37 | try { 38 | int result = s.compute(A, B); 39 | cout << result << endl; 40 | } catch (std::bad_alloc& e) { 41 | cout << "Not enough memory\n"; 42 | } catch (std::exception& e) { 43 | cout << "Exception: " << e.what() << endl; 44 | } catch (exception &e){ 45 | cout << "Other Exception\n"; 46 | } catch (int i) { 47 | cout << "Other Exception\n"; 48 | } 49 | } 50 | cout << Server::getLoad() << endl; 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Classes/InheritedCode.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | class BadLengthException : public exception { 8 | int n; 9 | public: 10 | BadLengthException(int num) { 11 | n = num; 12 | } 13 | int what() { 14 | return n; 15 | } 16 | }; 17 | 18 | bool checkUsername(string username) { 19 | bool isValid = true; 20 | int n = username.length(); 21 | if(n < 5) { 22 | throw BadLengthException(n); 23 | } 24 | for(int i = 0; i < n-1; i++) { 25 | if(username[i] == 'w' && username[i+1] == 'w') { 26 | isValid = false; 27 | } 28 | } 29 | return isValid; 30 | } 31 | 32 | int main() { 33 | int T; cin >> T; 34 | while(T--) { 35 | string username; 36 | cin >> username; 37 | try { 38 | bool isValid = checkUsername(username); 39 | if(isValid) { 40 | cout << "Valid" << '\n'; 41 | } else { 42 | cout << "Invalid" << '\n'; 43 | } 44 | } catch (BadLengthException e) { 45 | cout << "Too short: " << e.what() << '\n'; 46 | } 47 | } 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Classes/Structs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | struct Student { 9 | int age; 10 | char first_name[51]; 11 | char last_name[51]; 12 | int standard; 13 | }; 14 | 15 | int main() { 16 | Student st; 17 | 18 | cin >> st.age >> st.first_name >> st.last_name >> st.standard; 19 | cout << st.age << " " << st.first_name << " " << st.last_name << " " << st.standard; 20 | 21 | return 0; 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Classes/VirtualFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | class Person { 9 | protected: 10 | string name; 11 | int age; 12 | public: 13 | virtual void getdata() {} 14 | virtual void putdata() {} 15 | }; 16 | 17 | class Professor : public Person { 18 | int publications; 19 | static int cur_id; 20 | int id = cur_id; 21 | public: 22 | void getdata(){ 23 | cur_id ++; 24 | cin >> name; 25 | cin >> age; 26 | cin >> publications; 27 | } 28 | void putdata() { 29 | cout << name << ' ' << age << ' ' << publications << ' ' << id << endl; 30 | } 31 | 32 | }; 33 | int Professor :: cur_id = 1; 34 | 35 | class Student : public Person { 36 | int marks[6]; 37 | int sum = 0; 38 | static int cur_id; 39 | int id = cur_id; 40 | public: 41 | void getdata(){ 42 | cur_id ++; 43 | cin >> name; 44 | cin >> age; 45 | for(int i = 0; i < 6; i ++) { 46 | cin >> marks[i]; 47 | sum += marks[i]; 48 | } 49 | } 50 | void putdata() { 51 | cout << name << ' ' << age << ' ' << sum << ' ' << id << endl; 52 | } 53 | }; 54 | int Student :: cur_id = 1; 55 | 56 | int main(){ 57 | 58 | int n, val; 59 | cin>>n; //The number of objects that is going to be created. 60 | Person *per[n]; 61 | 62 | for(int i = 0;i < n;i++){ 63 | 64 | cin>>val; 65 | if(val == 1){ 66 | // If val is 1 current object is of type Professor 67 | per[i] = new Professor; 68 | 69 | } 70 | else per[i] = new Student; // Else the current object is of type Student 71 | 72 | per[i]->getdata(); // Get the data from the user. 73 | 74 | } 75 | 76 | for(int i=0;iputdata(); // Print the required output for each object. 78 | 79 | return 0; 80 | 81 | } 82 | 83 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Inheritance/AccessingInheritedFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class A 6 | { 7 | public: 8 | A(){ 9 | callA = 0; 10 | } 11 | private: 12 | int callA; 13 | void inc(){ 14 | callA++; 15 | } 16 | 17 | protected: 18 | void func(int & a) 19 | { 20 | a = a * 2; 21 | inc(); 22 | } 23 | public: 24 | int getA(){ 25 | return callA; 26 | } 27 | }; 28 | 29 | class B 30 | { 31 | public: 32 | B(){ 33 | callB = 0; 34 | } 35 | private: 36 | int callB; 37 | void inc(){ 38 | callB++; 39 | } 40 | protected: 41 | void func(int & a) 42 | { 43 | a = a * 3; 44 | inc(); 45 | } 46 | public: 47 | int getB(){ 48 | return callB; 49 | } 50 | }; 51 | 52 | class C 53 | { 54 | public: 55 | C(){ 56 | callC = 0; 57 | } 58 | private: 59 | int callC; 60 | void inc(){ 61 | callC++; 62 | } 63 | protected: 64 | void func(int & a) 65 | { 66 | a = a * 5; 67 | inc(); 68 | } 69 | public: 70 | int getC(){ 71 | return callC; 72 | } 73 | }; 74 | 75 | class D : public A, public B, public C 76 | { 77 | int val; 78 | public: 79 | //Initially val is 1 80 | D() 81 | { 82 | val = 1; 83 | } 84 | 85 | 86 | //Implement this function 87 | void update_val(int new_val) 88 | { while(new_val != 1) { 89 | if (new_val % 2 == 0) { 90 | A :: func(val); 91 | new_val /= 2; 92 | } else if (new_val % 3 == 0) { 93 | B :: func(val); 94 | new_val /= 3; 95 | } else { 96 | C :: func(val); 97 | new_val /= 5; 98 | } 99 | } 100 | } 101 | //For Checking Purpose 102 | void check(int); //Do not delete this line. 103 | }; 104 | 105 | 106 | 107 | void D::check(int new_val) 108 | { 109 | update_val(new_val); 110 | cout << "Value = " << val << endl << "A's func called " << getA() << " times " << endl << "B's func called " << getB() << " times" << endl << "C's func called " << getC() << " times" << endl; 111 | } 112 | 113 | 114 | int main() 115 | { 116 | D d; 117 | int new_val; 118 | cin >> new_val; 119 | d.check(new_val); 120 | 121 | } 122 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Inheritance/InheritanceIntroduction.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | class Triangle{ 10 | public: 11 | void triangle(){ 12 | cout << "I am a triangle\n"; 13 | } 14 | }; 15 | 16 | class Isosceles : public Triangle{ 17 | public: 18 | void isosceles(){ 19 | cout << "I am an isosceles triangle\n"; 20 | } 21 | void description() { 22 | cout << "In an isosceles triangle two sides are equal\n"; 23 | } 24 | }; 25 | 26 | int main(){ 27 | Isosceles isc; 28 | isc.isosceles(); 29 | isc.description(); 30 | isc.triangle(); 31 | return 0; 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Inheritance/MagicSpells.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Spell { 7 | private: 8 | string scrollName; 9 | public: 10 | Spell(): scrollName("") { } 11 | Spell(string name): scrollName(name) { } 12 | virtual ~Spell() { } 13 | string revealScrollName() { 14 | return scrollName; 15 | } 16 | }; 17 | 18 | class Fireball : public Spell { 19 | private: int power; 20 | public: 21 | Fireball(int power): power(power) { } 22 | void revealFirepower(){ 23 | cout << "Fireball: " << power << endl; 24 | } 25 | }; 26 | 27 | class Frostbite : public Spell { 28 | private: int power; 29 | public: 30 | Frostbite(int power): power(power) { } 31 | void revealFrostpower(){ 32 | cout << "Frostbite: " << power << endl; 33 | } 34 | }; 35 | 36 | class Thunderstorm : public Spell { 37 | private: int power; 38 | public: 39 | Thunderstorm(int power): power(power) { } 40 | void revealThunderpower(){ 41 | cout << "Thunderstorm: " << power << endl; 42 | } 43 | }; 44 | 45 | class Waterbolt : public Spell { 46 | private: int power; 47 | public: 48 | Waterbolt(int power): power(power) { } 49 | void revealWaterpower(){ 50 | cout << "Waterbolt: " << power << endl; 51 | } 52 | }; 53 | 54 | class SpellJournal { 55 | public: 56 | static string journal; 57 | static string read() { 58 | return journal; 59 | } 60 | }; 61 | string SpellJournal::journal = ""; 62 | 63 | void counterspell(Spell *spell) { 64 | if (Fireball* f = dynamic_cast(spell)) f -> revealFirepower(); 65 | else if (Frostbite* fr = dynamic_cast(spell)) fr -> revealFrostpower(); 66 | else if (Waterbolt* w = dynamic_cast(spell)) w -> revealWaterpower(); 67 | else if (Thunderstorm* t = dynamic_cast(spell)) t -> revealThunderpower(); 68 | else { 69 | string x = spell -> revealScrollName(); 70 | int m = x.length(); 71 | string y = SpellJournal::journal; 72 | int n = y.length(); 73 | int array[m + 1][n + 1]; 74 | for (int i = 0; i <= m; i++) array[i][0] = 0; 75 | for (int j = 0; j <= n; j++) array[0][j] = 0; 76 | for (int i = 1; i <= m; i++) 77 | for (int j = 1; j <= n; j++) { 78 | if (x[i - 1] == y[j - 1]) 79 | array[i][j] = array[i - 1][j - 1] + 1; 80 | else 81 | array[i][j] = array[i][j - 1] > array[i - 1][j] ? array[i][j - 1] : array[i - 1][j]; 82 | } 83 | 84 | cout << array[m][n] << endl; 85 | } 86 | } 87 | 88 | class Wizard { 89 | public: 90 | Spell *cast() { 91 | Spell *spell; 92 | string s; cin >> s; 93 | int power; cin >> power; 94 | if(s == "fire") { 95 | spell = new Fireball(power); 96 | } 97 | else if(s == "frost") { 98 | spell = new Frostbite(power); 99 | } 100 | else if(s == "water") { 101 | spell = new Waterbolt(power); 102 | } 103 | else if(s == "thunder") { 104 | spell = new Thunderstorm(power); 105 | } 106 | else { 107 | spell = new Spell(s); 108 | cin >> SpellJournal::journal; 109 | } 110 | return spell; 111 | } 112 | }; 113 | 114 | int main() { 115 | int T; 116 | cin >> T; 117 | Wizard Arawn; 118 | while(T--) { 119 | Spell *spell = Arawn.cast(); 120 | counterspell(spell); 121 | } 122 | return 0; 123 | } 124 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Inheritance/MultiLevelInheritance.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | class Triangle{ 9 | public: 10 | void triangle(){ 11 | cout<<"I am a triangle\n"; 12 | } 13 | }; 14 | 15 | class Isosceles : public Triangle{ 16 | public: 17 | void isosceles(){ 18 | cout<<"I am an isosceles triangle\n"; 19 | } 20 | }; 21 | 22 | class Equilateral : public Isosceles { 23 | public: 24 | void equilateral(){ 25 | cout<<"I am an equilateral triangle\n"; 26 | } 27 | }; 28 | 29 | int main(){ 30 | 31 | Equilateral eqr; 32 | eqr.equilateral(); 33 | eqr.isosceles(); 34 | eqr.triangle(); 35 | return 0; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Inheritance/RectangleArea.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class Rectangle { 6 | protected: 7 | int width; 8 | int height; 9 | 10 | public: 11 | void display() { 12 | cout << width << ' ' << height << endl; 13 | } 14 | }; 15 | 16 | class RectangleArea : public Rectangle { 17 | public: 18 | void read_input() { 19 | cin >> width >> height; 20 | } 21 | void display() { 22 | cout << width * height; 23 | } 24 | }; 25 | 26 | 27 | int main() 28 | { 29 | /* 30 | * Declare a RectangleArea object 31 | */ 32 | RectangleArea r_area; 33 | 34 | /* 35 | * Read the width and height 36 | */ 37 | r_area.read_input(); 38 | 39 | /* 40 | * Print the width and height 41 | */ 42 | r_area.Rectangle::display(); 43 | 44 | /* 45 | * Print the area 46 | */ 47 | r_area.display(); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Introduction/ArraysIntroduction.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | int n; 12 | cin >> n; 13 | int arr [n]; 14 | for (int i = 0; i < n; i ++) { 15 | cin >> arr[i]; 16 | } 17 | for (int i = n-1; i >= 0; i --) { 18 | cout << arr[i] << " "; 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Introduction/BasicDataTypes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // Complete the code. 7 | int n; 8 | long l; 9 | char c; 10 | float f; 11 | double d; 12 | scanf("%d%ld%*c%c%f%lf", &n, &l, &c, &f, &d); 13 | printf("%d\n%ld\n%c\n%.3f\n%.9lf\n", n , l, c, f, d); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Introduction/ConditionalStatements.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | 6 | 7 | int main() 8 | { 9 | int n; 10 | cin >> n; 11 | cin.ignore(numeric_limits::max(), '\n'); 12 | 13 | // Write Your Code Here 14 | 15 | if ( n==1 ) { 16 | printf("one"); 17 | } else if ( n==2 ) { 18 | printf("two"); 19 | } else if ( n==3 ) { 20 | printf("three"); 21 | } else if ( n==4 ) { 22 | printf("four"); 23 | } else if ( n==5 ) { 24 | printf("five"); 25 | } else if ( n==6 ) { 26 | printf("six"); 27 | } else if ( n==7 ) { 28 | printf("seven"); 29 | } else if ( n==8 ) { 30 | printf("eight"); 31 | } else if ( n==9 ) { 32 | printf("nine"); 33 | } else { 34 | printf("Greater than 9"); 35 | } 36 | 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Introduction/ForLoop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // Complete the code. 7 | int start, end; 8 | scanf("%d%d", &start, &end); 9 | for (int i = start; i <= end; i ++) { 10 | if(i >= 1 && i <= 9) { 11 | if(i == 1) { 12 | printf("one\n"); 13 | } else if (i == 2) { 14 | printf("two\n"); 15 | } else if (i == 3) { 16 | printf("three\n"); 17 | } else if (i == 4) { 18 | printf("four\n"); 19 | } else if (i == 5) { 20 | printf("five\n"); 21 | } else if (i == 6) { 22 | printf("six\n"); 23 | } else if (i == 7) { 24 | printf("seven\n"); 25 | } else if (i == 8) { 26 | printf("eight\n"); 27 | } else if (i == 9) { 28 | printf("nine\n"); 29 | } 30 | } else if (i > 9){ 31 | if(i % 2 == 0) { 32 | printf("even\n"); 33 | } else { 34 | printf("odd\n"); 35 | } 36 | } 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Introduction/Functions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int max_of_four(int a, int b, int c, int d) { 6 | int t1 = a > b ? a : b; 7 | int t2 = c > d ? c : d; 8 | int max = t1 > t2 ? t1 : t2; 9 | return max; 10 | } 11 | 12 | 13 | int main() { 14 | int a, b, c, d; 15 | scanf("%d %d %d %d", &a, &b, &c, &d); 16 | int ans = max_of_four(a, b, c, d); 17 | printf("%d", ans); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Introduction/InputAndOutput.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | int a, b, c; 12 | cin >> a >> b >> c; 13 | cout << a + b + c << endl; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Introduction/Pointer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void update(int *a,int *b) { 4 | // Complete this function 5 | int t = *a; 6 | *a = *a + *b; 7 | *b = t > *b ? t - *b : *b - t; 8 | } 9 | 10 | int main() { 11 | int a, b; 12 | int *pa = &a, *pb = &b; 13 | 14 | scanf("%d %d", &a, &b); 15 | update(pa, pb); 16 | printf("%d\n%d", a, b); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Introduction/SayHelloWorldWithCPlusPlus.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | cout << "Hello, World!"; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Introduction/VariableSizedArrays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | int n, q; 11 | cin >> n >> q; 12 | int* outer[n]; 13 | for(int i = 0; i < n; i ++) { 14 | int size; 15 | cin >> size; 16 | outer[i] = new int [size]; 17 | for (int j = 0; j < size; j ++) { 18 | cin >> outer [i][j]; 19 | } 20 | } 21 | 22 | for (int i = 0; i < q; i ++) { 23 | int j,k; 24 | cin >> j >> k; 25 | cout << outer[j][k] << endl; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Other Concepts/AttendingWorkshops.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | struct Workshops { 5 | int start_time; 6 | int duration; 7 | int end_time; 8 | }; 9 | 10 | struct Available_Workshops { 11 | int n; 12 | vector w; 13 | }; 14 | 15 | Available_Workshops *initialize(int *start_time, int *duration, int n) { 16 | Available_Workshops *tmp = new(Available_Workshops); 17 | Workshops ws; 18 | 19 | tmp -> n = n; 20 | for (int i=0;i w.push_back(ws); 25 | } 26 | 27 | return tmp; 28 | } 29 | 30 | bool compare(Workshops w1, Workshops w2) { 31 | return (w1.end_time < w2.end_time); 32 | } 33 | 34 | int CalculateMaxWorkshops(Available_Workshops* ptr) { 35 | // sort workshops by end_time 36 | sort(ptr->w.begin(),ptr->w.end(),compare); 37 | 38 | // interval scheduling 39 | int last_processed_time=-1; 40 | int maxWorkshops=0; 41 | for (int i=0;in;i++) { 42 | if (ptr->w[i].start_time >= last_processed_time) { 43 | last_processed_time=ptr->w[i].end_time; 44 | maxWorkshops++; 45 | } 46 | } 47 | 48 | return maxWorkshops; 49 | } 50 | int main(int argc, char *argv[]) { 51 | int n; // number of workshops 52 | cin >> n; 53 | // create arrays of unknown size n 54 | int* start_time = new int[n]; 55 | int* duration = new int[n]; 56 | 57 | for(int i=0; i < n; i++){ 58 | cin >> start_time[i]; 59 | } 60 | for(int i = 0; i < n; i++){ 61 | cin >> duration[i]; 62 | } 63 | 64 | Available_Workshops * ptr; 65 | ptr = initialize(start_time,duration, n); 66 | cout << CalculateMaxWorkshops(ptr) << endl; 67 | return 0; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Other Concepts/ClassTemplateSpecialization.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | enum class Fruit { apple, orange, pear }; 4 | enum class Color { red, green, orange }; 5 | 6 | template struct Traits; 7 | template <> 8 | struct Traits{ 9 | static string name(int index){ 10 | switch(index){ 11 | case 0:return "apple"; 12 | case 1: return "orange" ; 13 | case 2: return "pear"; 14 | } 15 | return "unknown"; 16 | } 17 | }; 18 | template <> 19 | struct Traits{ 20 | static string name(int index){ 21 | switch(index){ 22 | case 0:return "red"; 23 | case 1: return "green" ; 24 | case 2: return "orange"; 25 | } 26 | return "unknown"; 27 | } 28 | }; 29 | 30 | int main() 31 | { 32 | int t = 0; std::cin >> t; 33 | 34 | for (int i=0; i!=t; ++i) { 35 | int index1; std::cin >> index1; 36 | int index2; std::cin >> index2; 37 | cout << Traits::name(index1) << " "; 38 | cout << Traits::name(index2) << "\n"; 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Other Concepts/ClassTemplates.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | template 10 | class AddElements { 11 | T element; 12 | public: 13 | AddElements(T val) : element(val){} 14 | T add(T val) { 15 | return element + val; 16 | } 17 | T concatenate(T val) { 18 | return element + val; 19 | } 20 | }; 21 | 22 | int main () { 23 | int n,i; 24 | cin >> n; 25 | for(i=0;i> type; 28 | if(type=="float") { 29 | double element1,element2; 30 | cin >> element1 >> element2; 31 | AddElements myfloat (element1); 32 | cout << myfloat.add(element2) << endl; 33 | } 34 | else if(type == "int") { 35 | int element1, element2; 36 | cin >> element1 >> element2; 37 | AddElements myint (element1); 38 | cout << myint.add(element2) << endl; 39 | } 40 | else if(type == "string") { 41 | string element1, element2; 42 | cin >> element1 >> element2; 43 | AddElements mystring (element1); 44 | cout << mystring.concatenate(element2) << endl; 45 | } 46 | } 47 | return 0; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Other Concepts/OperatorOverloading.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | class Matrix{ 8 | public: 9 | vector> a; 10 | Matrix& operator +(const Matrix &y) { 11 | for(int m = 0; m < y.a.size(); m++) 12 | for(int n = 0; n < y.a[0].size(); n ++) { 13 | a[m][n] = a[m][n] + y.a[m][n]; 14 | } 15 | return *this; 16 | } 17 | }; 18 | 19 | int main () { 20 | int cases,k; 21 | cin >> cases; 22 | for(k=0;k> n >> m; 28 | for(i=0;i b; 30 | int num; 31 | for(j=0;j> num; 33 | b.push_back(num); 34 | } 35 | x.a.push_back(b); 36 | } 37 | for(i=0;i b; 39 | int num; 40 | for(j=0;j> num; 42 | b.push_back(num); 43 | } 44 | y.a.push_back(b); 45 | } 46 | result = x+y; 47 | for(i=0;i 4 | 5 | using namespace std; 6 | 7 | class Complex 8 | { 9 | public: 10 | int a,b; 11 | void input(string s) 12 | { 13 | int v1=0; 14 | int i=0; 15 | while(s[i]!='+') 16 | { 17 | v1=v1*10+s[i]-'0'; 18 | i++; 19 | } 20 | while(s[i]==' ' || s[i]=='+'||s[i]=='i') 21 | { 22 | i++; 23 | } 24 | int v2=0; 25 | while(i>s1; 55 | cin>>s2; 56 | x.input(s1); 57 | y.input(s2); 58 | Complex z=x+y; 59 | cout<> s 3 | #define foreach(list, index) for(int index = 0; index < list.size(); index++) 4 | #define FUNCTION(name, op) void name(int &x, int y){ if(!(x op y)) x = y; } 5 | #define INF 1e9 6 | 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | #if !defined toStr || !defined io || !defined FUNCTION || !defined INF 12 | #error Missing preprocessor definitions 13 | #endif 14 | 15 | FUNCTION(minimum, <) 16 | FUNCTION(maximum, >) 17 | 18 | int main(){ 19 | int n; cin >> n; 20 | vector v(n); 21 | foreach(v, i) { 22 | io(v)[i]; 23 | } 24 | int mn = INF; 25 | int mx = -INF; 26 | foreach(v, i) { 27 | minimum(mn, v[i]); 28 | maximum(mx, v[i]); 29 | } 30 | int ans = mx - mn; 31 | cout << toStr(Result =) <<' '<< ans; 32 | return 0; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/STL/DequeStl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void printKMax(int arr[], int n, int k){ 6 | deque d; 7 | for(int i=0;i=arr[d.back()]){ 10 | d.pop_back(); 11 | } 12 | d.push_back(i); 13 | } 14 | for(int i=k;i=arr[d.back()]) 22 | { 23 | d.pop_back(); 24 | } 25 | d.push_back(i); 26 | } 27 | cout<> t; 35 | while(t>0) { 36 | int n,k; 37 | cin >> n >> k; 38 | int i; 39 | int arr[n]; 40 | for(i=0;i> arr[i]; 42 | printKMax(arr, n, k); 43 | t--; 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/STL/LowerBoundStl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | int size, a; 11 | cin >> size; 12 | vector v; 13 | 14 | for(int i = 0; i < size; i ++) { 15 | cin >> a; 16 | v.push_back(a); 17 | } 18 | 19 | int q; 20 | cin >> q; 21 | 22 | for(int i = 0; i < q; i ++) { 23 | int n; 24 | cin >> n; 25 | vector :: iterator low = lower_bound(v.begin(), v.end(), n); 26 | if (v[low - v.begin()] == n) 27 | cout << "Yes" << " " << low - v.begin() + 1 << endl; 28 | else 29 | cout << "No" << " " << low - v.begin() + 1 << endl; 30 | } 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/STL/MapsStl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | int main() { 11 | int q; 12 | cin >> q; 13 | 14 | map m; 15 | 16 | for (int i = 0; i> t >> name; 21 | if (t == 1){ 22 | cin >> marks; 23 | m[name] += marks; 24 | } 25 | else if (t == 2) 26 | m.erase(name); 27 | else 28 | cout << m[name] << "\n"; 29 | } 30 | return 0; 31 | } 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/STL/PrintPretty.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int T; cin >> T; 7 | cout << setiosflags(ios::uppercase); 8 | cout << setw(0xf) << internal; 9 | while(T--) { 10 | double A; cin >> A; 11 | double B; cin >> B; 12 | double C; cin >> C; 13 | cout << hex << left << showbase << nouppercase; 14 | cout << (long long)A << endl; 15 | 16 | cout << dec << right << setw(15) << setfill('_') << showpos << fixed << setprecision(2); 17 | cout << B << endl; 18 | 19 | cout << uppercase << noshowpos << scientific << setprecision(9); 20 | cout << C << endl; 21 | 22 | 23 | } 24 | return 0; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/STL/SetsStl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | 10 | int main() { 11 | int q; 12 | cin >> q; 13 | set s; 14 | for(int i = 0; i < q; i ++) { 15 | int t, x; 16 | cin >> t >> x; 17 | switch(t) { 18 | case 1: 19 | s.insert(x); 20 | break; 21 | case 2: 22 | s.erase(x); 23 | break; 24 | case 3: 25 | set :: iterator p = s.find(x); 26 | if (p == s.end()) cout << "No" << endl; 27 | else cout << "Yes" << endl; 28 | break; 29 | 30 | } 31 | } 32 | return 0; 33 | } 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/STL/VectorErase.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | int size, a; 11 | cin >> size; 12 | vector v; 13 | 14 | for(int i = 0; i < size; i ++) { 15 | cin >> a; 16 | v.push_back(a); 17 | } 18 | 19 | int p; 20 | cin >> p; 21 | v.erase(v.begin() + p - 1); 22 | 23 | int m, n; 24 | cin >> m >> n; 25 | v.erase(v.begin() + m - 1, v.begin() + n -1); 26 | 27 | cout << v.size() << endl; 28 | for(int i = 0; i < v.size(); i ++) 29 | cout << v[i] << " "; 30 | return 0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/STL/VectorSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | int size, a; 11 | cin >> size; 12 | vector v; 13 | for(int i = 0; i < size; i ++) { 14 | cin >> a; 15 | v.push_back(a); 16 | } 17 | sort(v.begin(), v.end()); 18 | for(int i = 0; i < size; i ++) { 19 | cout << v[i] << " "; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Strings/AttributeParser.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chandraprakash-dev/HackerRank/e8e612c72b1c13c7ddb6f8e4854f663e728bfdf7/LANGUAGE PROFICIENCY/C++/Strings/AttributeParser.cpp -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Strings/StringStream.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | vector parseInts(string str) { 7 | stringstream ss(str); 8 | int a; 9 | char ch; 10 | vector v; 11 | while(ss >> a) 12 | { 13 | v.push_back(a); 14 | ss >> ch; 15 | } 16 | return v; 17 | } 18 | 19 | int main() { 20 | string str; 21 | cin >> str; 22 | vector integers = parseInts(str); 23 | for(int i = 0; i < integers.size(); i++) { 24 | cout << integers[i] << "\n"; 25 | } 26 | 27 | return 0; 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C++/Strings/Strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | string s1, s2; 7 | cin >> s1 >> s2; 8 | cout << s1.size() << ' '<< s2.size() << endl; 9 | cout << s1 + s2 << endl; 10 | char t = s1[0]; 11 | s1[0] = s2 [0]; 12 | s2[0] = t; 13 | cout << s1 << ' ' << s2; 14 | return 0; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Arrays and Strings/1DArraysInC.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | int n, sum = 0; 8 | scanf("%d", &n); 9 | int * arr = (int *)malloc(n * sizeof(int)); 10 | for(int i = 0; i < n; i ++) { 11 | scanf("%d", arr + i); 12 | sum += arr [i]; 13 | } 14 | printf("%d", sum); 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Arrays and Strings/ArrayReversal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int num, *arr, i; 7 | scanf("%d", &num); 8 | arr = (int*) malloc(num * sizeof(int)); 9 | for(i = 0; i < num; i++) { 10 | scanf("%d", arr + i); 11 | } 12 | 13 | for(int i = 0, j = num-1; i <= j; i++, j --) { 14 | int t = arr[i]; 15 | arr[i] = arr [j]; 16 | arr[j] = t; 17 | } 18 | 19 | for(i = 0; i < num; i++) 20 | printf("%d ", *(arr + i)); 21 | return 0; 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Arrays and Strings/DigitFrequency.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | 8 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 9 | char s[1000]; 10 | int arr[10] = {0}; 11 | scanf("%s",s); 12 | 13 | for(int i = 0; i < strlen(s); i ++) { 14 | int j = s[i] - 48; 15 | if( j >= 0 && j <= 9 ) { 16 | arr[j]++; 17 | } 18 | } 19 | 20 | for(int i = 0; i < 10; i ++) { 21 | printf("%d ", arr[i]); 22 | } 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Arrays and Strings/DynamicArrayInC.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | * This stores the total number of books in each shelf. 6 | */ 7 | int* total_number_of_books; 8 | 9 | /* 10 | * This stores the total number of pages in each book of each shelf. 11 | * The rows represent the shelves and the columns represent the books. 12 | */ 13 | int** total_number_of_pages; 14 | 15 | int main() 16 | { 17 | int total_number_of_shelves; 18 | scanf("%d", &total_number_of_shelves); 19 | 20 | int total_number_of_queries; 21 | scanf("%d", &total_number_of_queries); 22 | 23 | total_number_of_pages = (int **)malloc(total_number_of_shelves * sizeof(int*)); 24 | 25 | total_number_of_books = (int *) malloc(total_number_of_shelves * sizeof(int)); 26 | 27 | for(int i = 0; i < total_number_of_shelves; i ++) { 28 | total_number_of_books[i] = 0; 29 | } 30 | 31 | while (total_number_of_queries--) { 32 | int type_of_query; 33 | scanf("%d", &type_of_query); 34 | 35 | if (type_of_query == 1) { 36 | int x, y; 37 | scanf("%d %d", &x, &y); 38 | if(*(total_number_of_pages + x)) { 39 | *(total_number_of_pages + x) = (int *)realloc(*(total_number_of_pages + x), (total_number_of_books[x] + 1) * sizeof(int)); 40 | total_number_of_pages[x][total_number_of_books[x]] = y; 41 | } 42 | else { 43 | *(total_number_of_pages + x) = (int *)malloc(sizeof(int)); 44 | **(total_number_of_pages + x) = y; 45 | } 46 | total_number_of_books[x]++; 47 | } else if (type_of_query == 2) { 48 | int x, y; 49 | scanf("%d %d", &x, &y); 50 | printf("%d\n", *(*(total_number_of_pages + x) + y)); 51 | } else { 52 | int x; 53 | scanf("%d", &x); 54 | printf("%d\n", *(total_number_of_books + x)); 55 | } 56 | } 57 | 58 | if (total_number_of_books) { 59 | free(total_number_of_books); 60 | } 61 | 62 | for (int i = 0; i < total_number_of_shelves; i++) { 63 | if (*(total_number_of_pages + i)) { 64 | free(*(total_number_of_pages + i)); 65 | } 66 | } 67 | 68 | if (total_number_of_pages) { 69 | free(total_number_of_pages); 70 | } 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Arrays and Strings/PrintingTokens.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | 8 | char *s; 9 | s = malloc(1024 * sizeof(char)); 10 | scanf("%[^\n]", s); 11 | s = realloc(s, strlen(s) + 1); 12 | for(int i = 0; i < strlen(s); i ++) { 13 | if(s[i] == ' ') s[i] = '\n'; 14 | } 15 | printf("%s", s); 16 | free(s); 17 | return 0; 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Conditionals and Loops/BitwiseOperators.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void calculate_the_maximum(int n, int k) { 7 | int amax, omax, xmax; 8 | amax = omax = xmax = 0; 9 | for(int i = 1; i < n; i ++) { 10 | for(int j = i+1; j <= n; j ++) { 11 | amax = (i & j) > amax && (i & j) < k ? i & j : amax; 12 | omax = (i | j) > omax && (i | j) < k ? i | j : omax; 13 | xmax = (i ^ j) > xmax && (i ^ j) < k ? i ^ j : xmax; 14 | } 15 | } 16 | printf("%d\n", amax); 17 | printf("%d\n", omax); 18 | printf("%d\n", xmax); 19 | } 20 | 21 | int main() { 22 | int n, k; 23 | 24 | scanf("%d %d", &n, &k); 25 | calculate_the_maximum(n, k); 26 | 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Conditionals and Loops/ConditionalStatementsInC.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | char* readline(); 12 | 13 | 14 | 15 | int main() 16 | { 17 | char* n_endptr; 18 | char* n_str = readline(); 19 | int n = strtol(n_str, &n_endptr, 10); 20 | 21 | if (n_endptr == n_str || *n_endptr != '\0') { exit(EXIT_FAILURE); } 22 | 23 | // Write Your Code Here 24 | if(n ==1 ) { 25 | printf("one"); 26 | } else if(n == 2) { 27 | printf("two"); 28 | } else if(n == 3) { 29 | printf("three"); 30 | } else if(n == 4) { 31 | printf("four"); 32 | } else if(n == 5) { 33 | printf("five"); 34 | } else if(n == 6) { 35 | printf("six"); 36 | } else if(n == 7) { 37 | printf("seven"); 38 | } else if(n == 8) { 39 | printf("eight"); 40 | } else if(n == 9) { 41 | printf("nine"); 42 | } else { 43 | printf("Greater than 9"); 44 | } 45 | 46 | return 0; 47 | } 48 | 49 | char* readline() { 50 | size_t alloc_length = 1024; 51 | size_t data_length = 0; 52 | char* data = malloc(alloc_length); 53 | 54 | while (true) { 55 | char* cursor = data + data_length; 56 | char* line = fgets(cursor, alloc_length - data_length, stdin); 57 | 58 | if (!line) { break; } 59 | 60 | data_length += strlen(cursor); 61 | 62 | if (data_length < alloc_length - 1 || data[data_length - 1] == '\n') { break; } 63 | 64 | size_t new_length = alloc_length << 1; 65 | data = realloc(data, new_length); 66 | 67 | if (!data) { break; } 68 | 69 | alloc_length = new_length; 70 | } 71 | 72 | if (data[data_length - 1] == '\n') { 73 | data[data_length - 1] = '\0'; 74 | } 75 | 76 | data = realloc(data, data_length); 77 | 78 | return data; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Conditionals and Loops/ForLoopInC.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int a, b; 9 | scanf("%d\n%d", &a, &b); 10 | // Complete the code. 11 | for (int i = a; i <= b; i ++) { 12 | if(i >= 1 && i <= 9) { 13 | if(i == 1) { 14 | printf("one\n"); 15 | } else if(i == 2) { 16 | printf("two\n"); 17 | } else if(i == 3) { 18 | printf("three\n"); 19 | } else if(i == 4) { 20 | printf("four\n"); 21 | } else if(i == 5) { 22 | printf("five\n"); 23 | } else if(i == 6) { 24 | printf("six\n"); 25 | } else if(i == 7) { 26 | printf("seven\n"); 27 | } else if(i == 8) { 28 | printf("eight\n"); 29 | } else if(i == 9) { 30 | printf("nine\n"); 31 | } 32 | } else { 33 | if(i % 2 == 0) { 34 | printf("even\n"); 35 | } else { 36 | printf("odd\n"); 37 | } 38 | 39 | } 40 | } 41 | return 0; 42 | } 43 | 44 | 45 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Conditionals and Loops/PrintingPatternsUsingLoops.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void check(int i, int j, int first, int last, int n) { 7 | if(n >=1 ){ 8 | if (i == first || i == last || j == first || j == last) 9 | printf("%d ", n); 10 | else 11 | check(i, j, first + 1, last - 1, n - 1); 12 | } 13 | } 14 | 15 | int main() 16 | { 17 | int n; 18 | scanf("%d", &n); 19 | int rows = 2 * n - 1; 20 | 21 | for (int i = 0; i < rows; i ++) { 22 | for (int j = 0; j < rows; j ++) { 23 | check(i, j, 0, rows - 1, n); 24 | } 25 | printf("\n"); 26 | } 27 | return 0; 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Conditionals and Loops/SumOfDigitsOfAFiveDigitNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | 8 | int n, sum = 0; 9 | scanf("%d", &n); 10 | while(n > 0) { 11 | sum += n %10; 12 | n = n/10; 13 | } 14 | printf("%d", sum); 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Functions/CalculateTheNthTerm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int find_nth_term(int n, int a, int b, int c) { 7 | if (n == 1) return a; 8 | if (n == 2) return b; 9 | if (n == 3) return c; 10 | else return(find_nth_term(n-1, a, b, c) + find_nth_term(n-2, a, b, c) + find_nth_term(n-3, a, b, c)); 11 | } 12 | 13 | int main() { 14 | int n, a, b, c; 15 | 16 | scanf("%d %d %d %d", &n, &a, &b, &c); 17 | int ans = find_nth_term(n, a, b, c); 18 | 19 | printf("%d", ans); 20 | return 0; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Functions/PermutationsOfStrings.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int next_permutation(int n, char **s) 6 | { 7 | // This is a standard algorithm to generate permutations of a sequence in 8 | // lexicographic order 9 | // Use this to understand how the algorithm works https://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order 10 | 11 | int k, l; 12 | // 1. find the largest index k such that s[k] < s[k+1] 13 | for (k = n - 2; k >= 0; k --) { 14 | if(strcmp(s[k], s[k+1]) < 0) break; 15 | } 16 | if (k < 0) return 0; 17 | 18 | // 2. find the largest index l greater than k such that s[k] < s[l] 19 | for (l = n -1; l > k; l --) { 20 | if(strcmp(s[k], s[l]) < 0) break; 21 | } 22 | 23 | // 3. swap elements present at k, l 24 | char * tmp = s[k]; 25 | s[k] = s[l]; 26 | s[l] = tmp; 27 | 28 | // 4. reverse the sequence of elements from k+1 to n 29 | for(int i = k + 1, j = n -1; i < j; i ++, j --) { 30 | tmp = s[i]; 31 | s[i] = s[j]; 32 | s[j] = tmp; 33 | } 34 | return 1; 35 | } 36 | 37 | int main() 38 | { 39 | char **s; 40 | int n; 41 | scanf("%d", &n); 42 | s = calloc(n, sizeof(char*)); 43 | for (int i = 0; i < n; i++) 44 | { 45 | s[i] = calloc(11, sizeof(char)); 46 | scanf("%s", s[i]); 47 | } 48 | do 49 | { 50 | for (int i = 0; i < n; i++) 51 | printf("%s%c", s[i], i == n - 1 ? '\n' : ' '); 52 | } while (next_permutation(n, s)); 53 | for (int i = 0; i < n; i++) 54 | free(s[i]); 55 | free(s); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Functions/QueryingTheDocument.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #define MAX_CHARACTERS 1005 6 | #define MAX_PARAGRAPHS 5 7 | 8 | char* kth_word_in_mth_sentence_of_nth_paragraph(char**** document, int k, int m, int n) { 9 | return document[n - 1][m - 1][k - 1]; 10 | } 11 | 12 | char** kth_sentence_in_mth_paragraph(char**** document, int k, int m) { 13 | return document[m - 1][k - 1]; 14 | } 15 | 16 | char*** kth_paragraph(char**** document, int k) { 17 | return document[k - 1]; 18 | } 19 | 20 | char**** get_document(char* text) { 21 | // doc points to an array of paragraphs 22 | char ****doc = malloc(MAX_PARAGRAPHS * sizeof(char ***)); 23 | 24 | // for each paragraph, assign an array of 1 sentence, we can reallocate later 25 | for(int i = 0; i < MAX_PARAGRAPHS; i ++) { 26 | doc[i] = malloc(1 * sizeof(char **)); 27 | } 28 | 29 | // for each sentence assign an array of 1 word 30 | for(int i = 0; i < MAX_PARAGRAPHS; i ++) { 31 | for(int j = 0; j < 1; j ++) { 32 | doc[i][j] = malloc(1 * sizeof(char*)); 33 | } 34 | } 35 | 36 | // for each word assign an array of 1 character 37 | for(int i = 0; i < MAX_PARAGRAPHS; i ++) { 38 | for(int j = 0; j < 1; j ++) { 39 | for(int k = 0; k < 1; k ++) { 40 | doc[i][j][k] = malloc(1 * sizeof(char)); 41 | } 42 | } 43 | } 44 | 45 | for(int n = 0, i = 0, j = 0, k = 0, l = 0; n < strlen(text); n ++) { 46 | if(text[n] != ' ' && text[n] != '\n' && text[n] != '.') { 47 | doc[i][j][k][l] = text[n]; 48 | l++; 49 | doc[i][j][k] = realloc(doc[i][j][k], (l + 1) * sizeof(char)); 50 | } else if(text[n] == ' ') { 51 | doc[i][j][k][l] = '\0'; 52 | l = 0; 53 | k++; 54 | doc[i][j] = realloc(doc[i][j], (k + 1) * sizeof(char*)); 55 | doc[i][j][k] = malloc(sizeof(char)); 56 | continue; 57 | } else if(text[n] == '.') { 58 | doc[i][j][k][l] = '\0'; 59 | k = l = 0; 60 | j++; 61 | doc[i] = realloc(doc[i], (j+1) * sizeof(char**)); 62 | doc[i][j] = malloc(sizeof(char*)); 63 | doc[i][j][k] = malloc(sizeof(char)); 64 | continue; 65 | } else if(text[n] == '\n') { 66 | j = k = l = 0; 67 | i++; 68 | continue; 69 | } 70 | } 71 | return doc; 72 | } 73 | 74 | 75 | char* get_input_text() { 76 | int paragraph_count; 77 | scanf("%d", ¶graph_count); 78 | 79 | char p[MAX_PARAGRAPHS][MAX_CHARACTERS], doc[MAX_CHARACTERS]; 80 | memset(doc, 0, sizeof(doc)); 81 | getchar(); 82 | for (int i = 0; i < paragraph_count; i++) { 83 | scanf("%[^\n]%*c", p[i]); 84 | strcat(doc, p[i]); 85 | if (i != paragraph_count - 1) 86 | strcat(doc, "\n"); 87 | } 88 | 89 | char* returnDoc = (char*)malloc((strlen (doc)+1) * (sizeof(char))); 90 | strcpy(returnDoc, doc); 91 | return returnDoc; 92 | } 93 | 94 | void print_word(char* word) { 95 | printf("%s", word); 96 | } 97 | 98 | void print_sentence(char** sentence) { 99 | int word_count; 100 | scanf("%d", &word_count); 101 | for(int i = 0; i < word_count; i++){ 102 | printf("%s", sentence[i]); 103 | if( i != word_count - 1) 104 | printf(" "); 105 | } 106 | } 107 | 108 | void print_paragraph(char*** paragraph) { 109 | int sentence_count; 110 | scanf("%d", &sentence_count); 111 | for (int i = 0; i < sentence_count; i++) { 112 | print_sentence(*(paragraph + i)); 113 | printf("."); 114 | } 115 | } 116 | 117 | int main() 118 | { 119 | char* text = get_input_text(); 120 | char**** document = get_document(text); 121 | 122 | int q; 123 | scanf("%d", &q); 124 | 125 | while (q--) { 126 | int type; 127 | scanf("%d", &type); 128 | 129 | if (type == 3){ 130 | int k, m, n; 131 | scanf("%d %d %d", &k, &m, &n); 132 | char* word = kth_word_in_mth_sentence_of_nth_paragraph(document, k, m, n); 133 | print_word(word); 134 | } 135 | 136 | else if (type == 2){ 137 | int k, m; 138 | scanf("%d %d", &k, &m); 139 | char** sentence = kth_sentence_in_mth_paragraph(document, k, m); 140 | print_sentence(sentence); 141 | } 142 | 143 | else{ 144 | int k; 145 | scanf("%d", &k); 146 | char*** paragraph = kth_paragraph(document, k); 147 | print_paragraph(paragraph); 148 | } 149 | printf("\n"); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Functions/SortingArrayOfStrings.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int lexicographic_sort(const char* a, const char* b) { 5 | return (strcmp(a, b)); 6 | } 7 | 8 | int lexicographic_sort_reverse(const char* a, const char* b) { 9 | return (strcmp(b, a)); 10 | } 11 | 12 | int sort_by_number_of_distinct_characters(const char* a, const char* b) { 13 | int count[2] = {0}; // array to maintain count of characters in a, b 14 | 15 | int presencea[26] = {0}; // array to check presence of a character 16 | for (int j = 0; j < strlen(a); j++) { 17 | if (a[j] != ' ' && presencea[a[j] - 97] == 0) { 18 | presencea[a[j] - 97] = 1; 19 | count[0]++; 20 | } 21 | } 22 | 23 | int presenceb[26] = {0}; // array to check presence of a character 24 | for (int j = 0; j < strlen(b); j++) { 25 | if (b[j] != ' ' && presenceb[b[j] - 97] == 0) { 26 | presenceb[b[j] - 97] = 1; 27 | count[1]++; 28 | } 29 | } 30 | 31 | if (count[0] > count[1] || (count[0] == count[1] && strcmp(a, b) > 0) ) return 1; 32 | else return 0; 33 | } 34 | 35 | int sort_by_length(const char* a, const char* b) { 36 | if(strlen(a) > strlen(b) ){ 37 | return 1; 38 | } else if(strlen(a) == strlen(b)){ 39 | if(strcmp(a, b) > 0) return 1; 40 | else return 0; 41 | } else return 0; 42 | } 43 | 44 | void string_sort(char** arr,const int len,int (*cmp_func)(const char* a, const char* b)){ 45 | char * tmp; 46 | for(int i = 0; i < len - 1; i ++) { 47 | for (int j = i + 1; j < len ; j ++) 48 | if(cmp_func(arr[i], arr[j] ) > 0){ 49 | tmp = arr[i]; 50 | arr[i] = arr[j]; 51 | arr[j] = tmp; 52 | } 53 | } 54 | } 55 | 56 | 57 | int main() 58 | { 59 | int n; 60 | scanf("%d", &n); 61 | 62 | char** arr; 63 | arr = (char**)malloc(n * sizeof(char*)); 64 | 65 | for(int i = 0; i < n; i++){ 66 | *(arr + i) = malloc(1024 * sizeof(char)); 67 | scanf("%s", *(arr + i)); 68 | *(arr + i) = realloc(*(arr + i), strlen(*(arr + i)) + 1); 69 | } 70 | 71 | string_sort(arr, n, lexicographic_sort); 72 | for(int i = 0; i < n; i++) 73 | printf("%s\n", arr[i]); 74 | printf("\n"); 75 | 76 | string_sort(arr, n, lexicographic_sort_reverse); 77 | for(int i = 0; i < n; i++) 78 | printf("%s\n", arr[i]); 79 | printf("\n"); 80 | 81 | string_sort(arr, n, sort_by_length); 82 | for(int i = 0; i < n; i++) 83 | printf("%s\n", arr[i]); 84 | printf("\n"); 85 | 86 | string_sort(arr, n, sort_by_number_of_distinct_characters); 87 | for(int i = 0; i < n; i++) 88 | printf("%s\n", arr[i]); 89 | printf("\n"); 90 | } 91 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Functions/StudentsMarksSum.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int marks_summation(int* marks, int number_of_students, char gender) { 7 | int sum = 0; 8 | if (gender == 'b'){ 9 | for(int i = 0; i < number_of_students; i += 2) sum += marks[i]; 10 | } else { 11 | for (int i = 1; i < number_of_students; i += 2) sum += marks[i]; 12 | } 13 | return sum; 14 | } 15 | 16 | int main() { 17 | int number_of_students; 18 | char gender; 19 | int sum; 20 | 21 | scanf("%d", &number_of_students); 22 | int *marks = (int *) malloc(number_of_students * sizeof (int)); 23 | 24 | for (int student = 0; student < number_of_students; student++) { 25 | scanf("%d", (marks + student)); 26 | } 27 | 28 | scanf(" %c", &gender); 29 | sum = marks_summation(marks, number_of_students, gender); 30 | printf("%d", sum); 31 | free(marks); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Functions/VariadicFunctionsInC.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define MIN_ELEMENT 1 7 | #define MAX_ELEMENT 1000000 8 | int sum (int count,...) { 9 | int sum = 0; 10 | 11 | // define a pointer to the variable list 12 | va_list ptr; 13 | // start the pointer to the list 14 | va_start(ptr, count); 15 | // access the argument pointed to in the list and increment position 16 | for (int i = 0; i < count; i ++) { 17 | sum += va_arg(ptr, int); 18 | } 19 | va_end(ptr); 20 | return sum; 21 | } 22 | 23 | int min(int count,...) { 24 | va_list ptr; 25 | va_start(ptr, count); 26 | 27 | int min = va_arg(ptr, int); 28 | int tmp; 29 | for(int i = 1; i < count; i ++) { 30 | if((tmp = va_arg(ptr, int)) < min) { 31 | min = tmp; 32 | } 33 | } 34 | va_end(ptr); 35 | return min; 36 | } 37 | 38 | int max(int count,...) { 39 | va_list ptr; 40 | va_start(ptr, count); 41 | 42 | int max = va_arg(ptr, int); 43 | int tmp; 44 | for(int i = 1; i < count; i ++) { 45 | if((tmp = va_arg(ptr, int)) > max) { 46 | max = tmp; 47 | } 48 | } 49 | va_end(ptr); 50 | return max; 51 | } 52 | 53 | int test_implementations_by_sending_three_elements() { 54 | srand(time(NULL)); 55 | 56 | int elements[3]; 57 | 58 | elements[0] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 59 | elements[1] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 60 | elements[2] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 61 | 62 | fprintf(stderr, "Sending following three elements:\n"); 63 | for (int i = 0; i < 3; i++) { 64 | fprintf(stderr, "%d\n", elements[i]); 65 | } 66 | 67 | int elements_sum = sum(3, elements[0], elements[1], elements[2]); 68 | int minimum_element = min(3, elements[0], elements[1], elements[2]); 69 | int maximum_element = max(3, elements[0], elements[1], elements[2]); 70 | 71 | fprintf(stderr, "Your output is:\n"); 72 | fprintf(stderr, "Elements sum is %d\n", elements_sum); 73 | fprintf(stderr, "Minimum element is %d\n", minimum_element); 74 | fprintf(stderr, "Maximum element is %d\n\n", maximum_element); 75 | 76 | int expected_elements_sum = 0; 77 | for (int i = 0; i < 3; i++) { 78 | if (elements[i] < minimum_element) { 79 | return 0; 80 | } 81 | 82 | if (elements[i] > maximum_element) { 83 | return 0; 84 | } 85 | 86 | expected_elements_sum += elements[i]; 87 | } 88 | 89 | return elements_sum == expected_elements_sum; 90 | } 91 | 92 | int test_implementations_by_sending_five_elements() { 93 | srand(time(NULL)); 94 | 95 | int elements[5]; 96 | 97 | elements[0] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 98 | elements[1] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 99 | elements[2] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 100 | elements[3] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 101 | elements[4] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 102 | 103 | fprintf(stderr, "Sending following five elements:\n"); 104 | for (int i = 0; i < 5; i++) { 105 | fprintf(stderr, "%d\n", elements[i]); 106 | } 107 | 108 | int elements_sum = sum(5, elements[0], elements[1], elements[2], elements[3], elements[4]); 109 | int minimum_element = min(5, elements[0], elements[1], elements[2], elements[3], elements[4]); 110 | int maximum_element = max(5, elements[0], elements[1], elements[2], elements[3], elements[4]); 111 | 112 | fprintf(stderr, "Your output is:\n"); 113 | fprintf(stderr, "Elements sum is %d\n", elements_sum); 114 | fprintf(stderr, "Minimum element is %d\n", minimum_element); 115 | fprintf(stderr, "Maximum element is %d\n\n", maximum_element); 116 | 117 | int expected_elements_sum = 0; 118 | for (int i = 0; i < 5; i++) { 119 | if (elements[i] < minimum_element) { 120 | return 0; 121 | } 122 | 123 | if (elements[i] > maximum_element) { 124 | return 0; 125 | } 126 | 127 | expected_elements_sum += elements[i]; 128 | } 129 | 130 | return elements_sum == expected_elements_sum; 131 | } 132 | 133 | int test_implementations_by_sending_ten_elements() { 134 | srand(time(NULL)); 135 | 136 | int elements[10]; 137 | 138 | elements[0] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 139 | elements[1] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 140 | elements[2] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 141 | elements[3] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 142 | elements[4] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 143 | elements[5] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 144 | elements[6] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 145 | elements[7] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 146 | elements[8] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 147 | elements[9] = rand() % (MAX_ELEMENT - MIN_ELEMENT + 1) + MIN_ELEMENT; 148 | 149 | fprintf(stderr, "Sending following ten elements:\n"); 150 | for (int i = 0; i < 10; i++) { 151 | fprintf(stderr, "%d\n", elements[i]); 152 | } 153 | 154 | int elements_sum = sum(10, elements[0], elements[1], elements[2], elements[3], elements[4], 155 | elements[5], elements[6], elements[7], elements[8], elements[9]); 156 | int minimum_element = min(10, elements[0], elements[1], elements[2], elements[3], elements[4], 157 | elements[5], elements[6], elements[7], elements[8], elements[9]); 158 | int maximum_element = max(10, elements[0], elements[1], elements[2], elements[3], elements[4], 159 | elements[5], elements[6], elements[7], elements[8], elements[9]); 160 | 161 | fprintf(stderr, "Your output is:\n"); 162 | fprintf(stderr, "Elements sum is %d\n", elements_sum); 163 | fprintf(stderr, "Minimum element is %d\n", minimum_element); 164 | fprintf(stderr, "Maximum element is %d\n\n", maximum_element); 165 | 166 | int expected_elements_sum = 0; 167 | for (int i = 0; i < 10; i++) { 168 | if (elements[i] < minimum_element) { 169 | return 0; 170 | } 171 | 172 | if (elements[i] > maximum_element) { 173 | return 0; 174 | } 175 | 176 | expected_elements_sum += elements[i]; 177 | } 178 | 179 | return elements_sum == expected_elements_sum; 180 | } 181 | 182 | int main () 183 | { 184 | int number_of_test_cases; 185 | scanf("%d", &number_of_test_cases); 186 | 187 | while (number_of_test_cases--) { 188 | if (test_implementations_by_sending_three_elements()) { 189 | printf("Correct Answer\n"); 190 | } else { 191 | printf("Wrong Answer\n"); 192 | } 193 | 194 | if (test_implementations_by_sending_five_elements()) { 195 | printf("Correct Answer\n"); 196 | } else { 197 | printf("Wrong Answer\n"); 198 | } 199 | 200 | if (test_implementations_by_sending_ten_elements()) { 201 | printf("Correct Answer\n"); 202 | } else { 203 | printf("Wrong Answer\n"); 204 | } 205 | } 206 | 207 | return 0; 208 | } 209 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Introduction/FunctionsInC.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* 3 | Add `int max_of_four(int a, int b, int c, int d)` here. 4 | */ 5 | 6 | int max_of_four(int a, int b, int c, int d) { 7 | int ans; 8 | a = a > b ? a : b; 9 | c = c > d ? c : d; 10 | ans = a > c ? a : c; 11 | return ans; 12 | } 13 | 14 | int main() { 15 | int a, b, c, d; 16 | scanf("%d %d %d %d", &a, &b, &c, &d); 17 | int ans = max_of_four(a, b, c, d); 18 | printf("%d", ans); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Introduction/HelloWorld.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | 5 | char s[100]; 6 | scanf("%[^\n]%*c", &s); 7 | // [^\n] - everything upto \n, but not \n 8 | // %c - scan \n 9 | // * - discard what is scanned 10 | 11 | /* Enter your code here. Read input from STDIN. Print output to STDOUT*/ 12 | printf("Hello, World!\n"); 13 | printf("%s", s); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Introduction/PlayingWithCharacters.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #define MAX_LEN 100 6 | 7 | int main() 8 | { 9 | char ch, s[MAX_LEN], sen[MAX_LEN]; 10 | scanf("%c", &ch); 11 | printf("%c\n", ch); 12 | 13 | scanf("%s", s); 14 | printf("%s\n", s); 15 | scanf("\n"); 16 | 17 | scanf("%[^\n]%*c]", sen); 18 | printf("%s\n", sen); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Introduction/PointersInC.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void update(int *a,int *b) { 4 | // Complete this function 5 | int t = *a; 6 | *a = *a + *b; 7 | *b = t > *b ? t - *b : *b - t; 8 | } 9 | 10 | int main() { 11 | int a, b; 12 | int *pa = &a, *pb = &b; 13 | 14 | scanf("%d %d", &a, &b); 15 | update(pa, pb); 16 | printf("%d\n%d", a, b); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Introduction/SumAndDifferenceOfTwoNumbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int a,b; 9 | float c,d; 10 | 11 | scanf("%d", &a); 12 | scanf("%d", &b); 13 | printf("%d %d\n", a + b, a - b); 14 | 15 | scanf("%f", &c); 16 | scanf("%f", &d); 17 | printf("%.1f %.1f", c + d, c - d); 18 | 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Structs and Enums/BoxesThroughATunnel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define MAX_HEIGHT 41 4 | 5 | struct box 6 | { 7 | int length; 8 | int height; 9 | int width; 10 | }; 11 | 12 | typedef struct box box; 13 | 14 | int get_volume(box b) { 15 | return (b.length * b.height * b.width); 16 | } 17 | 18 | int is_lower_than_max_height(box b) { 19 | if(b.height < MAX_HEIGHT) return 1; 20 | else return 0; 21 | } 22 | 23 | int main() 24 | { 25 | int n; 26 | scanf("%d", &n); 27 | box *boxes = malloc(n * sizeof(box)); 28 | for (int i = 0; i < n; i++) { 29 | scanf("%d%d%d", &boxes[i].length, &boxes[i].width, &boxes[i].height); 30 | } 31 | for (int i = 0; i < n; i++) { 32 | if (is_lower_than_max_height(boxes[i])) { 33 | printf("%d\n", get_volume(boxes[i])); 34 | } 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Structs and Enums/PostTransition.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define MAX_STRING_LENGTH 6 5 | 6 | struct package 7 | { 8 | char* id; 9 | int weight; 10 | }; 11 | 12 | typedef struct package package; 13 | 14 | struct post_office 15 | { 16 | int min_weight; 17 | int max_weight; 18 | package* packages; 19 | int packages_count; 20 | }; 21 | 22 | typedef struct post_office post_office; 23 | 24 | struct town 25 | { 26 | char* name; 27 | post_office* offices; 28 | int offices_count; 29 | }; 30 | 31 | typedef struct town town; 32 | 33 | void print_all_packages(town t) { 34 | printf("%s:\n", t.name); 35 | for(int i = 0; i < t.offices_count; i ++) { 36 | printf("\t%d:\n", i); 37 | for(int j = 0; j < t.offices[i].packages_count; j ++) { 38 | printf("\t\t%s\n", t.offices[i].packages[j].id); 39 | } 40 | } 41 | } 42 | 43 | void send_all_acceptable_packages(town* source, int source_office_index, town* target, int target_office_index) { 44 | 45 | int min = target -> offices[target_office_index].min_weight; 46 | int max = target -> offices[target_office_index].max_weight; 47 | 48 | for(int i = 0; i < source -> offices[source_office_index].packages_count ; i ++) { 49 | int weight = source -> offices[source_office_index].packages[i].weight; 50 | if(weight >= min && weight <= max) { 51 | target -> offices[target_office_index].packages = realloc(target -> offices[target_office_index].packages, (target -> offices[target_office_index].packages_count + 1) * sizeof(package)); 52 | target -> offices[target_office_index].packages[target -> offices[target_office_index].packages_count] = source -> offices[source_office_index].packages[i]; 53 | (target -> offices[target_office_index].packages_count)++; 54 | 55 | for(int j = i; j < source -> offices[source_office_index].packages_count - 1; j ++) { 56 | source -> offices[source_office_index].packages[j] = source -> offices[source_office_index].packages[j+1]; 57 | } 58 | source -> offices[source_office_index].packages = realloc(source -> offices[source_office_index].packages, (source -> offices[source_office_index].packages_count - 1)* sizeof(package)); 59 | source -> offices[source_office_index].packages_count --; 60 | i--; 61 | } 62 | } 63 | } 64 | 65 | town town_with_most_packages(town* towns, int towns_count) { 66 | int index = 0, max = 0; 67 | for(int i = 0; i < towns_count; i ++) { 68 | int sum = 0; 69 | for(int j = 0; j < towns[i].offices_count; j ++) { 70 | sum += towns[i].offices[j].packages_count; 71 | } 72 | if(sum > max) { 73 | max = sum; 74 | index = i; 75 | } 76 | } 77 | return towns[index]; 78 | } 79 | 80 | town* find_town(town* towns, int towns_count, char* name) { 81 | int i; 82 | for(i = 0; i < towns_count; i ++) { 83 | if(! (strcmp(towns[i].name, name)) ) break; 84 | } 85 | return towns + i; 86 | } 87 | 88 | int main() 89 | { 90 | int towns_count; 91 | scanf("%d", &towns_count); 92 | town* towns = malloc(sizeof(town)*towns_count); 93 | for (int i = 0; i < towns_count; i++) { 94 | towns[i].name = malloc(sizeof(char) * MAX_STRING_LENGTH); 95 | scanf("%s", towns[i].name); 96 | scanf("%d", &towns[i].offices_count); 97 | towns[i].offices = malloc(sizeof(post_office)*towns[i].offices_count); 98 | for (int j = 0; j < towns[i].offices_count; j++) { 99 | scanf("%d%d%d", &towns[i].offices[j].packages_count, &towns[i].offices[j].min_weight, &towns[i].offices[j].max_weight); 100 | towns[i].offices[j].packages = malloc(sizeof(package)*towns[i].offices[j].packages_count); 101 | for (int k = 0; k < towns[i].offices[j].packages_count; k++) { 102 | towns[i].offices[j].packages[k].id = malloc(sizeof(char) * MAX_STRING_LENGTH); 103 | scanf("%s", towns[i].offices[j].packages[k].id); 104 | scanf("%d", &towns[i].offices[j].packages[k].weight); 105 | } 106 | } 107 | } 108 | int queries; 109 | scanf("%d", &queries); 110 | char town_name[MAX_STRING_LENGTH]; 111 | while (queries--) { 112 | int type; 113 | scanf("%d", &type); 114 | switch (type) { 115 | case 1: 116 | scanf("%s", town_name); 117 | town* t = find_town(towns, towns_count, town_name); 118 | print_all_packages(*t); 119 | break; 120 | case 2: 121 | scanf("%s", town_name); 122 | town* source = find_town(towns, towns_count, town_name); 123 | int source_index; 124 | scanf("%d", &source_index); 125 | scanf("%s", town_name); 126 | town* target = find_town(towns, towns_count, town_name); 127 | int target_index; 128 | scanf("%d", &target_index); 129 | send_all_acceptable_packages(source, source_index, target, target_index); 130 | break; 131 | case 3: 132 | printf("Town with the most number of packages is %s\n", town_with_most_packages(towns, towns_count).name); 133 | break; 134 | } 135 | } 136 | for(int i = 0; i < towns_count; i ++) { 137 | for (int j = 0; j < towns[i].offices_count; j ++) { 138 | free(towns[i].offices[j].packages); 139 | } 140 | free(towns[i].offices); 141 | } 142 | free(towns); 143 | return 0; 144 | } 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Structs and Enums/SmallTrianglesLargeTriangles.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct triangle 6 | { 7 | int a; 8 | int b; 9 | int c; 10 | }; 11 | 12 | typedef struct triangle triangle; 13 | int area(triangle t) { 14 | return((t.a+t.b+t.c)*(t.a+t.b-t.c)*(t.a+t.c-t.b)*(t.b+t.c-t.a)); 15 | } 16 | void sort_by_area(triangle* tr, int n) { 17 | for(int i = 0; i < n - 1; i ++) 18 | for(int j = i + 1; j < n; j ++) 19 | if(area(tr[i]) > area(tr[j])) { 20 | triangle t = tr[i]; 21 | tr[i] = tr[j]; 22 | tr[j] = t; 23 | } 24 | } 25 | 26 | int main() 27 | { 28 | int n; 29 | scanf("%d", &n); 30 | triangle *tr = malloc(n * sizeof(triangle)); 31 | for (int i = 0; i < n; i++) { 32 | scanf("%d%d%d", &tr[i].a, &tr[i].b, &tr[i].c); 33 | } 34 | sort_by_area(tr, n); 35 | for (int i = 0; i < n; i++) { 36 | printf("%d %d %d\n", tr[i].a, tr[i].b, tr[i].c); 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/C/Structs and Enums/StructuringTheDocument.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #define MAX_CHARACTERS 1005 6 | #define MAX_PARAGRAPHS 5 7 | 8 | struct word { 9 | char* data; 10 | }; 11 | 12 | struct sentence { 13 | struct word* data; 14 | int word_count;//denotes number of words in a sentence 15 | }; 16 | 17 | struct paragraph { 18 | struct sentence* data ; 19 | int sentence_count;//denotes number of sentences in a paragraph 20 | }; 21 | 22 | struct document { 23 | struct paragraph* data; 24 | int paragraph_count;//denotes number of paragraphs in a document 25 | }; 26 | 27 | struct document get_document(char* text) { 28 | struct document doc; 29 | 30 | int pcount = 0; 31 | for(int i = 0; i < strlen(text) ; i ++) { 32 | if(text[i] == '\n') pcount ++; 33 | } 34 | pcount ++; 35 | 36 | doc.paragraph_count = pcount; 37 | doc.data = malloc(pcount * sizeof(struct paragraph)); 38 | 39 | for(int n = 0, m = 0, l = 0, i = 0; i < pcount; i ++) { 40 | int scount = 0; 41 | while(text[n] != '\n' && n < strlen(text)) { 42 | if(text[n] == '.') scount ++; 43 | n ++; 44 | } 45 | n ++; 46 | 47 | doc.data[i].sentence_count = scount; 48 | doc.data[i].data = malloc(scount * sizeof(struct sentence)); 49 | 50 | for(int j = 0; j < scount; j ++) { 51 | int wcount = 0; 52 | while(text[m] != '.' && m < n) { 53 | if(text[m] == ' ') wcount ++; 54 | m ++; 55 | } 56 | m ++; 57 | if(text[m] == '\n') m ++; 58 | wcount ++; 59 | 60 | doc.data[i].data[j].word_count = wcount; 61 | doc.data[i].data[j].data = malloc(wcount * sizeof(struct word)); 62 | 63 | for(int k = 0; k < wcount; k ++) { 64 | int ccount = 0; 65 | while(text[l] != ' ' && text[l] != '.' && l < m) { 66 | ccount ++; 67 | l ++; 68 | } 69 | l ++; 70 | if(text[l] == '\n') l ++; 71 | 72 | ccount ++; 73 | doc.data[i].data[j].data[k].data = malloc(ccount * sizeof(char)); 74 | } 75 | } 76 | } 77 | 78 | int r = 0; 79 | for(int i = 0; i < doc.paragraph_count; i ++) { 80 | for(int j = 0; j < doc.data[i].sentence_count; j ++) { 81 | for(int k = 0; k < doc.data[i].data[j].word_count; k ++) { 82 | int l = 0; 83 | while(text[r] != ' ' && text[r] != '.' && text[r] != '\n') { 84 | doc.data[i].data[j].data[k].data[l] = text[r]; 85 | r++; 86 | l++; 87 | } 88 | doc.data[i].data[j].data[k].data[l] = '\0'; 89 | if(text[r] == '.') { 90 | r++; 91 | break; 92 | } 93 | r ++; 94 | } 95 | if(text[r] == '\n') { 96 | r ++; 97 | break; 98 | } 99 | } 100 | } 101 | 102 | return doc; 103 | } 104 | 105 | struct word kth_word_in_mth_sentence_of_nth_paragraph(struct document Doc, int k, int m, int n) { 106 | return Doc.data[n - 1].data[m - 1].data[k - 1]; 107 | } 108 | 109 | struct sentence kth_sentence_in_mth_paragraph(struct document Doc, int k, int m) { 110 | return Doc.data[m - 1].data[k - 1]; 111 | } 112 | 113 | struct paragraph kth_paragraph(struct document Doc, int k) { 114 | return Doc.data[k - 1]; 115 | } 116 | 117 | 118 | void print_word(struct word w) { 119 | printf("%s", w.data); 120 | } 121 | 122 | void print_sentence(struct sentence sen) { 123 | for(int i = 0; i < sen.word_count; i++) { 124 | print_word(sen.data[i]); 125 | if (i != sen.word_count - 1) { 126 | printf(" "); 127 | } 128 | } 129 | } 130 | 131 | void print_paragraph(struct paragraph para) { 132 | for(int i = 0; i < para.sentence_count; i++){ 133 | print_sentence(para.data[i]); 134 | printf("."); 135 | } 136 | } 137 | 138 | void print_document(struct document doc) { 139 | for(int i = 0; i < doc.paragraph_count; i++) { 140 | print_paragraph(doc.data[i]); 141 | if (i != doc.paragraph_count - 1) 142 | printf("\n"); 143 | } 144 | } 145 | 146 | char* get_input_text() { 147 | int paragraph_count; 148 | scanf("%d", ¶graph_count); 149 | 150 | char p[MAX_PARAGRAPHS][MAX_CHARACTERS], doc[MAX_CHARACTERS]; 151 | memset(doc, 0, sizeof(doc)); 152 | getchar(); 153 | for (int i = 0; i < paragraph_count; i++) { 154 | scanf("%[^\n]%*c", p[i]); 155 | strcat(doc, p[i]); 156 | if (i != paragraph_count - 1) 157 | strcat(doc, "\n"); 158 | } 159 | 160 | char* returnDoc = (char*)malloc((strlen (doc)+1) * (sizeof(char))); 161 | strcpy(returnDoc, doc); 162 | return returnDoc; 163 | } 164 | 165 | int main() 166 | { 167 | char* text = get_input_text(); 168 | struct document Doc = get_document(text); 169 | 170 | int q; 171 | scanf("%d", &q); 172 | 173 | while (q--) { 174 | int type; 175 | scanf("%d", &type); 176 | 177 | if (type == 3){ 178 | int k, m, n; 179 | scanf("%d %d %d", &k, &m, &n); 180 | struct word w = kth_word_in_mth_sentence_of_nth_paragraph(Doc, k, m, n); 181 | print_word(w); 182 | } 183 | 184 | else if (type == 2) { 185 | int k, m; 186 | scanf("%d %d", &k, &m); 187 | struct sentence sen= kth_sentence_in_mth_paragraph(Doc, k, m); 188 | print_sentence(sen); 189 | } 190 | 191 | else{ 192 | int k; 193 | scanf("%d", &k); 194 | struct paragraph para = kth_paragraph(Doc, k); 195 | print_paragraph(para); 196 | } 197 | printf("\n"); 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/BigNumber/JavaBigDecimal.java: -------------------------------------------------------------------------------- 1 | import java.math.BigDecimal; 2 | import java.util.*; 3 | class Solution{ 4 | 5 | public static void main(String []args){ 6 | //Input 7 | Scanner sc= new Scanner(System.in); 8 | int n=sc.nextInt(); 9 | String []s=new String[n+2]; 10 | for(int i=0;imaxi) maxi=sum; 20 | } 21 | } 22 | } 23 | System.out.println(maxi); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Data Structures/JavaArraylist.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution { 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int l = sc.nextInt(); 9 | ArrayList [ ] list = new ArrayList[l]; 10 | 11 | for(int i = 0; i < l; i ++) { 12 | int n = sc.nextInt(); 13 | list[i] = new ArrayList(); 14 | while(n -- > 0) { 15 | list[i].add(sc.nextInt()); 16 | } 17 | } 18 | 19 | int q = sc.nextInt(); 20 | while(q -- > 0) { 21 | int x = sc.nextInt(); 22 | int y = sc.nextInt(); 23 | 24 | try { 25 | System.out.println(list[x - 1].get(y - 1)); 26 | } catch (Exception e) { 27 | System.out.println("ERROR!"); 28 | } 29 | } 30 | 31 | } 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Data Structures/JavaList.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | 11 | Scanner sc = new Scanner(System.in); 12 | LinkedList list = new LinkedList(); 13 | int n = sc.nextInt(); 14 | for(int i = 0; i < n; i ++) { 15 | list.add(sc.nextInt()); 16 | } 17 | int q = sc.nextInt(); 18 | while(q-- > 0) { 19 | String s = sc.next(); 20 | if(s.equals("Insert")) { 21 | int index = sc.nextInt(); 22 | int value = sc.nextInt(); 23 | list.add(index, value); 24 | } else { 25 | int value = sc.nextInt(); 26 | list.remove(value); 27 | } 28 | } 29 | Iterator iterator = list.iterator(); 30 | while(iterator.hasNext()) { 31 | System.out.print(iterator.next() + " "); 32 | } 33 | } 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Data Structures/JavaSubarray.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution { 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int [] arr = new int [n]; 10 | for(int i = 0; i < n; i ++) { 11 | arr[i] = sc.nextInt(); 12 | } 13 | 14 | int count = 0, sum = 0; 15 | for(int i = 0; i < n; i ++) { 16 | for(int j = i; j < n; j ++) { 17 | sum += arr[j]; 18 | if(sum < 0) count ++; 19 | } 20 | sum = 0; 21 | } 22 | System.out.println(count); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Introduction/JavaCurrencyFormatter.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | double payment = scanner.nextDouble(); 12 | scanner.close(); 13 | 14 | Locale in = new Locale("en", "IN"); 15 | 16 | String us = NumberFormat.getCurrencyInstance(Locale.US).format(payment); 17 | String india = NumberFormat.getCurrencyInstance(in).format(payment); 18 | String china = NumberFormat.getCurrencyInstance(Locale.CHINA).format(payment); 19 | String france = NumberFormat.getCurrencyInstance(Locale.FRANCE).format(payment); 20 | 21 | System.out.println("US: " + us); 22 | System.out.println("India: " + india); 23 | System.out.println("China: " + china); 24 | System.out.println("France: " + france); 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Introduction/JavaDatatypes.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | import java.lang.Math; 4 | 5 | 6 | 7 | class Solution{ 8 | public static void main(String []argh) 9 | { 10 | 11 | 12 | 13 | Scanner sc = new Scanner(System.in); 14 | int t=sc.nextInt(); 15 | 16 | for(int i=0;i=-128 && x<=127)System.out.println("* byte"); 23 | if(x >= -Math.pow(2,15) && x <= Math.pow(2,15)-1)System.out.println("* short");; 24 | if(x >= -Math.pow(2,31) && x <= Math.pow(2,31)-1)System.out.println("* int");; 25 | if(x >= -Math.pow(2,63) && x <= Math.pow(2,63)-1)System.out.println("* long");; 26 | } 27 | catch(Exception e) 28 | { 29 | System.out.println(sc.next()+" can't be fitted anywhere."); 30 | } 31 | 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Introduction/JavaDateAndTime.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.function.*; 8 | import java.util.regex.*; 9 | import java.util.stream.*; 10 | import static java.util.stream.Collectors.joining; 11 | import static java.util.stream.Collectors.toList; 12 | 13 | class Result { 14 | 15 | /* 16 | * Complete the 'findDay' function below. 17 | * 18 | * The function is expected to return a STRING. 19 | * The function accepts following parameters: 20 | * 1. INTEGER month 21 | * 2. INTEGER day 22 | * 3. INTEGER year 23 | */ 24 | static String [] days = {"SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"}; 25 | public static String findDay(int month, int day, int year) { 26 | Calendar c = Calendar.getInstance(); 27 | c.set(year, month - 1, day); 28 | 29 | int p = c.get(Calendar.DAY_OF_WEEK); 30 | return days[p - 1]; 31 | } 32 | } 33 | 34 | public class Solution { 35 | public static void main(String[] args) throws IOException { 36 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); 37 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); 38 | 39 | String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" "); 40 | 41 | int month = Integer.parseInt(firstMultipleInput[0]); 42 | 43 | int day = Integer.parseInt(firstMultipleInput[1]); 44 | 45 | int year = Integer.parseInt(firstMultipleInput[2]); 46 | 47 | String res = Result.findDay(month, day, year); 48 | 49 | bufferedWriter.write(res); 50 | bufferedWriter.newLine(); 51 | 52 | bufferedReader.close(); 53 | bufferedWriter.close(); 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Introduction/JavaEndOfFile.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution { 5 | 6 | public static void main(String[] args) { 7 | int n = 1; 8 | Scanner sc = new Scanner(System.in); 9 | while(sc.hasNext()){ 10 | System.out.println(n++ + " " + sc.nextLine()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Introduction/JavaIfElse.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class Solution { 10 | 11 | 12 | 13 | private static final Scanner scanner = new Scanner(System.in); 14 | 15 | public static void main(String[] args) { 16 | int N = scanner.nextInt(); 17 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 18 | if(N % 2 == 1) { 19 | System.out.println("Weird"); 20 | } else { 21 | if (N >= 6 && N <= 20) { 22 | System.out.println("Weird"); 23 | } else { 24 | System.out.println("Not Weird"); 25 | } 26 | } 27 | scanner.close(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Introduction/JavaIntToString.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.security.*; 3 | public class Solution { 4 | public static void main(String[] args) { 5 | 6 | DoNotTerminate.forbidExit(); 7 | 8 | try { 9 | Scanner in = new Scanner(System.in); 10 | int n = in .nextInt(); 11 | in.close(); 12 | //String s=???; Complete this line below 13 | String s = Integer.toString(n); 14 | 15 | 16 | 17 | if (n == Integer.parseInt(s)) { 18 | System.out.println("Good job"); 19 | } else { 20 | System.out.println("Wrong answer."); 21 | } 22 | } catch (DoNotTerminate.ExitTrappedException e) { 23 | System.out.println("Unsuccessful Termination!!"); 24 | } 25 | } 26 | } 27 | 28 | //The following class will prevent you from terminating the code using exit(0)! 29 | class DoNotTerminate { 30 | 31 | public static class ExitTrappedException extends SecurityException { 32 | 33 | private static final long serialVersionUID = 1; 34 | } 35 | 36 | public static void forbidExit() { 37 | final SecurityManager securityManager = new SecurityManager() { 38 | @Override 39 | public void checkPermission(Permission permission) { 40 | if (permission.getName().contains("exitVM")) { 41 | throw new ExitTrappedException(); 42 | } 43 | } 44 | }; 45 | System.setSecurityManager(securityManager); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Introduction/JavaLoops1.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.math.*; 3 | import java.security.*; 4 | import java.text.*; 5 | import java.util.*; 6 | import java.util.concurrent.*; 7 | import java.util.regex.*; 8 | 9 | public class Solution { 10 | 11 | 12 | 13 | private static final Scanner scanner = new Scanner(System.in); 14 | 15 | public static void main(String[] args) { 16 | int N = scanner.nextInt(); 17 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 18 | for ( int i = 1; i < 11; i ++ ) { 19 | System.out.println(N +" x "+ i + " = " + N*i); 20 | } 21 | scanner.close(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Introduction/JavaLoops2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class Solution{ 5 | public static void main(String []argh){ 6 | Scanner in = new Scanner(System.in); 7 | int t=in.nextInt(); 8 | for(int i=0;i 0 && H > 0) flag = true; 15 | else System.out.println("java.lang.Exception: Breadth and height must be positive"); 16 | } 17 | public static void main(String[] args){ 18 | if(flag){ 19 | int area=B*H; 20 | System.out.print(area); 21 | } 22 | 23 | }//end of main 24 | 25 | }//end of class 26 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Introduction/JavaStdInAndStdOut1.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | Scanner scan = new Scanner(System.in); 7 | int a = scan.nextInt(); 8 | int b = scan.nextInt(); 9 | int c = scan.nextInt(); 10 | 11 | System.out.println(a); 12 | System.out.println(b); 13 | System.out.println(c); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Introduction/WelcomeToJava.java: -------------------------------------------------------------------------------- 1 | public class WelcomeToJava { 2 | public static void main(String [] args) { 3 | System.out.println("Hello, World."); 4 | System.out.println("Hello, Java."); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Strings/JavaAnagrams.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution { 4 | 5 | static boolean isAnagram(String a, String b) { 6 | if(a.length() != b.length()) 7 | return false; 8 | 9 | a = a.toLowerCase(); 10 | b = b.toLowerCase(); 11 | 12 | int [] frequency = new int [26]; 13 | 14 | for(char c: a.toCharArray()) { 15 | frequency[c-97]++; 16 | } 17 | for(char c: b.toCharArray()) { 18 | frequency[c-97]--; 19 | } 20 | 21 | for (int i : frequency) { 22 | if(i != 0) return false; 23 | } 24 | 25 | return true; 26 | } 27 | 28 | public static void main(String[] args) { 29 | 30 | Scanner scan = new Scanner(System.in); 31 | String a = scan.next(); 32 | String b = scan.next(); 33 | scan.close(); 34 | boolean ret = isAnagram(a, b); 35 | System.out.println( (ret) ? "Anagrams" : "Not Anagrams" ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Strings/JavaRegex.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.Matcher; 2 | import java.util.regex.Pattern; 3 | import java.util.Scanner; 4 | 5 | class Solution{ 6 | 7 | public static void main(String[] args){ 8 | Scanner in = new Scanner(System.in); 9 | while(in.hasNext()){ 10 | String IP = in.next(); 11 | System.out.println(IP.matches(new MyRegex().pattern)); 12 | } 13 | 14 | } 15 | } 16 | 17 | class MyRegex { 18 | String pattern = "\\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4}\\b"; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Strings/JavaRegex2DuplicateWords.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.regex.Matcher; 3 | import java.util.regex.Pattern; 4 | 5 | public class DuplicateWords { 6 | 7 | public static void main(String[] args) { 8 | 9 | String regex = "(\\b\\w+\\b)(\\s+\\1\\b)+"; 10 | Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); 11 | 12 | Scanner in = new Scanner(System.in); 13 | int numSentences = Integer.parseInt(in.nextLine()); 14 | 15 | while (numSentences-- > 0) { 16 | String input = in.nextLine(); 17 | 18 | Matcher m = p.matcher(input); 19 | 20 | // Check for subsequences of input that match the compiled pattern 21 | while (m.find()) { 22 | input = input.replaceAll(m.group(0), m.group(1)); 23 | } 24 | 25 | // Prints the modified sentence. 26 | System.out.println(input); 27 | } 28 | 29 | in.close(); 30 | } 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Strings/JavaStringTokens.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | String s = scan.nextLine().trim(); 9 | scan.close(); 10 | 11 | String [ ] tokens = s.split("[^\\p{Alpha}]+"); 12 | int size = s.isEmpty() ? 0 : tokens.length; 13 | 14 | System.out.println(size); 15 | for(String token : tokens ) { 16 | System.out.println(token); 17 | } 18 | } 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Strings/JavaStringsIntroduction.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner sc=new Scanner(System.in); 9 | String A=sc.next(); 10 | String B=sc.next(); 11 | 12 | System.out.println(A.length() + B.length()); 13 | if(A.compareTo(B) > 0) System.out.println("Yes"); 14 | else System.out.println("No"); 15 | System.out.println(A.substring(0,1).toUpperCase() + A.substring(1) + ' ' + B.substring(0,1).toUpperCase() + B.substring(1)); 16 | } 17 | } 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Strings/JavaSubstring.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | String S = in.next(); 12 | int start = in.nextInt(); 13 | int end = in.nextInt(); 14 | System.out.println(S.substring(start,end)); 15 | } 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Strings/JavaSubstringComparisons.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution { 4 | 5 | public static String getSmallestAndLargest(String s, int k) { 6 | String substring = s.substring(0, k); 7 | String smallest = substring; 8 | String largest = substring; 9 | 10 | int n = s.length() - k + 1; 11 | 12 | for(int i = 1; i < n; i ++) { 13 | substring = s.substring(i, i + k); 14 | smallest = substring.compareTo(smallest) < 0 ? substring : smallest; 15 | largest = substring.compareTo(largest) > 0 ? substring : largest; 16 | } 17 | return smallest + "\n" + largest; 18 | } 19 | 20 | 21 | public static void main(String[] args) { 22 | Scanner scan = new Scanner(System.in); 23 | String s = scan.next(); 24 | int k = scan.nextInt(); 25 | scan.close(); 26 | 27 | System.out.println(getSmallestAndLargest(s, k)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Strings/PatternSyntaxChecker.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.regex.*; 3 | 4 | public class Solution 5 | { 6 | public static void main(String[] args){ 7 | Scanner in = new Scanner(System.in); 8 | int testCases = Integer.parseInt(in.nextLine()); 9 | while(testCases>0){ 10 | String pattern = in.nextLine(); 11 | try { 12 | Pattern p = Pattern.compile(pattern); 13 | System.out.println("Valid"); 14 | } catch (Exception e) { 15 | System.out.println("Invalid"); 16 | } 17 | 18 | } 19 | } 20 | } 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Strings/TagContentExtractor.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution{ 8 | public static void main(String[] args){ 9 | 10 | Scanner in = new Scanner(System.in); 11 | int testCases = Integer.parseInt(in.nextLine()); 12 | while(testCases>0){ 13 | String line = in.nextLine(); 14 | 15 | String s = "<([^>]+)>([^<>]+)"; 16 | Pattern p = Pattern.compile(s); 17 | Matcher m = p.matcher(line); 18 | boolean found = true; 19 | while(m.find()) { 20 | System.out.println(m.group(2)); 21 | found = false; 22 | } 23 | 24 | if(found) { 25 | System.out.println("None"); 26 | } 27 | 28 | testCases--; 29 | } 30 | } 31 | } 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Java/Strings/ValidUsernameRegularExpression.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class UsernameValidator { 3 | 4 | public static final String regularExpression = "\\b[a-zA-Z]\\w{7,29}\\b"; 5 | } 6 | 7 | 8 | public class Solution { 9 | private static final Scanner scan = new Scanner(System.in); 10 | 11 | public static void main(String[] args) { 12 | int n = Integer.parseInt(scan.nextLine()); 13 | while (n-- != 0) { 14 | String userName = scan.nextLine(); 15 | 16 | if (userName.matches(UsernameValidator.regularExpression)) { 17 | System.out.println("Valid"); 18 | } else { 19 | System.out.println("Invalid"); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Python/.idea/Python.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Python/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Python/.idea/libraries/R_User_Library.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Python/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Python/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Python/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LANGUAGE PROFICIENCY/Python/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |