├── Inspiring Codes ├── EmployeesWithMissingInformation.sql ├── README.md ├── arrayMult.c ├── arrayMult.py ├── countDigits.cpp ├── digitalRoot.c ├── isAnagram.js ├── maxLen.cpp ├── maximumSubarrayProblem.cpp ├── maximumSubarrayProblem.py ├── myConcat.java ├── possibleSubsets.cpp ├── serializeDeserializeTree.cpp ├── sieveOfEratosthenes.cpp ├── twoSum.java ├── vowelRecognition.cpp └── vowelRecognition.py ├── README.md ├── Solutions ├── Aizu Online Judge │ ├── 0000 - QQ.cpp │ └── README.md ├── AlgoDaily │ ├── README.md │ ├── fizzBuzz.js │ ├── intersection.js │ ├── isAnagram.js │ ├── isPalindrome.js │ └── reverseString.js ├── AtCoder │ ├── README.md │ ├── taxiOrTrain.c │ └── taxiOrTrain.cpp ├── CS Academy │ ├── Addition.cpp │ └── README.md ├── CSES │ ├── 1083 - Missing Number.cpp │ └── README.md ├── CheckiO │ ├── README.md │ ├── multTwo.js │ ├── multTwo.py │ └── multTwo.ts ├── CodCad │ ├── README.md │ ├── division.cpp │ ├── helloCodCad.cpp │ ├── plugs.cpp │ └── sum.cpp ├── Code Jam │ └── README.md ├── CodeChef │ ├── Chef and Sum.c │ ├── Chef and Sum.cpp │ ├── Lucky Four.cpp │ └── README.md ├── CodeSignal │ ├── README.md │ ├── addBorder.java │ ├── addTwoDigits.c │ ├── addTwoDigits.cpp │ ├── adjacentElementsProduct.java │ ├── allLongestStrings.java │ ├── almostIncreasingSequence.java │ ├── alphabetSubsequence.c │ ├── alphabetSubsequence.cpp │ ├── alphabetSubstring.c │ ├── alphabetSubstring2.c │ ├── alternatingSums.java │ ├── areSimilar.java │ ├── areSimilarNumbers.cpp │ ├── arrayChange.java │ ├── arrayElementsProduct.java │ ├── baseConversion.py │ ├── candies.c │ ├── catWalk.py │ ├── centuryForYear.c │ ├── checkPalindrome.c │ ├── chessNotation.java │ ├── circleOfNumbers.c │ ├── commonCharacterCount.java │ ├── competitiveEating.py │ ├── convertTabs.py │ ├── countBits.py │ ├── countInversionsNaive.java │ ├── countWaysToChangeDigit.c │ ├── create2DArray.cpp │ ├── differentValuesInMultiplicationTable2.java │ ├── evenDigitsOnly.c │ ├── evenDigitsOnlyRecursive.c │ ├── factorialTrailingZeros.c │ ├── fastUnlock.c │ ├── feedbackReview.py │ ├── fibonacciNumber.c │ ├── fixMessage.py │ ├── fractionSubtraction.java │ ├── getCommit.py │ ├── graphEdges.cpp │ ├── increasingNumber.c │ ├── isCorrectSentence.c │ ├── isInformationConsistent.java │ ├── isLucky.c │ ├── isMonotonous.java │ ├── isPrime.c │ ├── isPrimeRecursive.c │ ├── isWordPalindrome.py │ ├── largestNumber.c │ ├── lateRide.c │ ├── lateRide.cpp │ ├── lateRide.py │ ├── latinLettersSearchRegExp.c │ ├── listBeautifier.py │ ├── longestString.cpp │ ├── makeArrayConsecutive.java │ ├── makeArrayConsecutive2.java │ ├── matrixElementsSum.java │ ├── maxDivisor.c │ ├── maxMultiple.c │ ├── mexFunction.py │ ├── minimalNumberOfCoins.java │ ├── modulus.py │ ├── myConcat.java │ ├── newStyleFormatting.py │ ├── numerology.java │ ├── permutationCipher.py │ ├── phoneCall.cpp │ ├── pointInLine.cpp │ ├── primeFactors.java │ ├── quasifactorial.c │ ├── quasifactorial.cpp │ ├── quasifactorial.hs │ ├── quasifactorial.java │ ├── quasifactorial.js │ ├── quasifactorial.py │ ├── reduceString.cpp │ ├── seatsInTheater.c │ ├── shapeArea.c │ ├── simpleSort.py │ ├── sortByHeight.cpp │ ├── sortByHeight.java │ ├── squareColor.c │ ├── sum.c │ ├── swapDiagonals.java │ ├── swapNeighbouringDigits.c │ ├── swapNeighbouringDigits.java │ ├── whoseMove.cpp │ └── zigzagTriple.kt ├── Codeforces │ ├── README.md │ ├── aHulk.c │ └── wrongSubtraction.c ├── Coderbyte │ ├── README.md │ └── firstFactorial.c ├── Codewars │ ├── README.md │ ├── digitalRoot.cpp │ ├── digitalRootRecursive.c │ └── setAlarm.c ├── Codingame │ ├── README.md │ ├── onboarding.c │ └── the-descent.c ├── DWITE │ └── README.md ├── Daily Coding Problems │ ├── Problem 2019-07-08 │ │ ├── README.md │ │ ├── sumTwo.java │ │ └── sumTwo2.java │ ├── Problem 2019-07-09 │ │ ├── README.md │ │ └── arrayMult.c │ ├── Problem 2019-07-10 │ │ └── README.md │ ├── Problem 2019-07-11 │ │ ├── README.md │ │ └── smallestMissingInteger.c │ ├── Problem 2019-07-12 │ │ ├── Main.java │ │ ├── Pair.java │ │ └── README.md │ ├── Problem 2019-07-13 (Advice) │ │ └── README.md │ ├── Problem 2019-07-14 │ │ └── README.md │ ├── Problem 2019-07-15 │ │ └── README.md │ ├── Problem 2019-07-16 │ │ └── README.md │ ├── Problem 2019-07-17 │ │ └── README.md │ ├── Problem 2019-07-18 │ │ └── README.md │ ├── Problem 2019-07-19 │ │ └── README.md │ ├── Problem 2019-07-20 │ │ └── README.md │ ├── Problem 2019-07-21 (Advice) │ │ └── README.md │ ├── Problem 2019-07-21 │ │ └── README.md │ ├── Problem 2019-07-22 │ │ └── README.md │ ├── Problem 2019-07-23 │ │ └── README.md │ ├── Problem 2019-07-24 │ │ └── README.md │ ├── Problem 2019-07-25 │ │ └── README.md │ ├── Problem 2019-07-26 │ │ └── README.md │ ├── Problem 2019-07-27 │ │ └── README.md │ ├── Problem 2019-07-28 (Advice) │ │ └── README.md │ ├── Problem 2019-07-28 │ │ └── README.md │ ├── Problem 2019-07-29 │ │ └── README.md │ ├── Problem 2019-07-30 │ │ └── README.md │ ├── Problem 2019-07-31 │ │ └── README.md │ ├── Problem 2019-08-01 │ │ └── README.md │ ├── Problem 2019-08-02 │ │ └── README.md │ ├── Problem 2019-08-03 │ │ └── README.md │ ├── Problem 2019-08-04 (Advice) │ │ └── README.md │ ├── Problem 2019-08-04 │ │ └── README.md │ ├── Problem 2019-08-05 │ │ └── README.md │ ├── Problem 2019-08-06 │ │ └── README.md │ ├── Problem 2019-08-07 │ │ └── README.md │ ├── Problem 2019-08-08 │ │ └── README.md │ ├── Problem 2019-08-09 │ │ └── README.md │ ├── Problem 2019-08-10 │ │ └── README.md │ ├── Problem 2019-08-11 │ │ └── README.md │ ├── Problem 2019-08-12 │ │ └── README.md │ ├── Problem 2019-08-13 │ │ └── README.md │ ├── Problem 2019-08-14 │ │ └── README.md │ ├── Problem 2019-08-15 │ │ └── README.md │ ├── Problem 2019-08-16 │ │ └── README.md │ ├── Problem 2019-08-17 │ │ └── README.md │ ├── Problem 2019-08-18 │ │ └── README.md │ ├── Problem 2019-08-19 │ │ └── README.md │ ├── Problem 2019-08-20 │ │ └── README.md │ ├── Problem 2019-08-21 │ │ └── README.md │ ├── Problem 2019-08-22 │ │ └── README.md │ ├── Problem 2019-08-23 │ │ └── README.md │ ├── Problem 2019-08-24 │ │ └── README.md │ ├── Problem 2019-08-25 │ │ └── README.md │ ├── Problem 2019-08-26 │ │ └── README.md │ ├── Problem 2019-08-27 │ │ └── README.md │ ├── Problem 2019-08-28 │ │ └── README.md │ ├── Problem 2019-08-29 │ │ └── README.md │ ├── Problem 2019-08-30 │ │ └── README.md │ ├── Problem 2019-08-31 │ │ └── README.md │ ├── Problem 2019-09-01 │ │ └── README.md │ ├── Problem 2019-09-02 │ │ └── README.md │ ├── Problem 2019-09-03 │ │ └── README.md │ ├── Problem 2019-09-04 │ │ └── README.md │ ├── Problem 2019-09-05 │ │ └── README.md │ ├── Problem 2019-09-06 │ │ └── README.md │ ├── Problem 2019-09-07 │ │ └── README.md │ ├── Problem 2019-09-08 │ │ └── README.md │ ├── Problem 2019-09-09 │ │ └── README.md │ ├── Problem 2019-09-10 │ │ └── README.md │ ├── Problem 2019-09-11 │ │ └── README.md │ ├── Problem 2019-09-12 │ │ └── README.md │ ├── Problem 2019-09-13 │ │ └── README.md │ ├── Problem 2019-09-14 │ │ └── README.md │ ├── Problem 2019-09-15 │ │ └── README.md │ ├── Problem 2019-09-16 │ │ └── README.md │ ├── Problem 2019-09-17 │ │ └── README.md │ ├── Problem 2019-09-18 │ │ └── README.md │ ├── Problem 2019-09-19 │ │ └── README.md │ ├── Problem 2019-09-20 │ │ └── README.md │ ├── Problem 2019-09-21 │ │ └── README.md │ ├── Problem 2019-09-22 │ │ └── README.md │ ├── Problem 2019-09-23 │ │ └── README.md │ ├── Problem 2019-09-24 │ │ └── README.md │ ├── Problem 2019-09-25 │ │ └── README.md │ ├── Problem 2019-09-26 │ │ └── README.md │ ├── Problem 2019-09-27 │ │ └── README.md │ ├── Problem 2019-09-28 │ │ └── README.md │ ├── Problem 2019-09-29 │ │ └── README.md │ ├── Problem 2019-09-30 │ │ └── README.md │ └── README.md ├── DevSkill │ ├── README.md │ └── Reverse.cpp ├── E-Olymp │ ├── 1 - Simple Problem.cpp │ └── README.md ├── Edabit │ ├── README.md │ ├── addition.js │ ├── bitwiseOperations.js │ ├── calcAge.js │ ├── circuitPower.js │ ├── convert.js │ ├── hello.js │ └── regexEmptyString.js ├── Exercism │ ├── README.md │ ├── c │ │ ├── acronym │ │ │ ├── README.md │ │ │ ├── makefile │ │ │ ├── src │ │ │ │ ├── acronym.c │ │ │ │ └── acronym.h │ │ │ └── test │ │ │ │ └── test_acronym.c │ │ └── hello-world │ │ │ ├── README.md │ │ │ ├── makefile │ │ │ ├── src │ │ │ ├── hello_world.c │ │ │ └── hello_world.h │ │ │ └── test │ │ │ └── test_hello_world.c │ ├── cpp │ │ ├── hello-world │ │ │ ├── README.md │ │ │ ├── hello_world.cpp │ │ │ ├── hello_world.h │ │ │ └── hello_world_test.cpp │ │ └── reverse-string │ │ │ ├── README.md │ │ │ ├── reverse_string.cpp │ │ │ └── reverse_string_test.cpp │ ├── java │ │ ├── hello-world │ │ │ ├── README.md │ │ │ ├── TUTORIAL.md │ │ │ ├── build.gradle │ │ │ └── src │ │ │ │ ├── main │ │ │ │ └── java │ │ │ │ │ └── Greeter.java │ │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── GreeterTest.java │ │ └── reverse-string │ │ │ ├── README.md │ │ │ ├── build.gradle │ │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ └── ReverseString.java │ │ │ └── test │ │ │ └── java │ │ │ └── ReverseStringTest.java │ ├── javascript │ │ ├── hello-world │ │ │ ├── README.md │ │ │ ├── hello-world.js │ │ │ └── hello-world.spec.js │ │ └── reverse-string │ │ │ ├── README.md │ │ │ ├── reverse-string.js │ │ │ └── reverse-string.spec.js │ └── python │ │ ├── hello-world │ │ ├── README.md │ │ ├── hello_world.py │ │ └── hello_world_test.py │ │ └── reverse-string │ │ ├── README.md │ │ ├── reverse_string.py │ │ └── reverse_string_test.py ├── Fuzhou University OnlineJudge │ ├── 1000 - A plus B.cpp │ └── README.md ├── GeeksForGeeks │ ├── README.md │ ├── equilibriumPoint.cpp │ ├── leadersInArray.cpp │ ├── majorityElement.cpp │ ├── maxLen.cpp │ ├── missingInteger.cpp │ ├── rotateArray.c │ ├── squaresInNNChessboard.c │ └── sumTermsNthRow.c ├── HackerEarth │ ├── README.md │ ├── add-two-arrays-1.c │ ├── basics-of-input-output.c │ ├── count-digits.cpp │ ├── count-set-bits.cpp │ ├── micro-and-array-update.cpp │ ├── n-queens.cpp │ ├── prime-number.c │ ├── range-of-integers-1.c │ ├── reversed-array.cpp │ ├── seating-arrangement.c │ ├── sum-of-four.c │ ├── sum-of-n-1.c │ ├── sum-of-squares-1.c │ ├── sum-of-two-1.c │ ├── transpose-matrix.cpp │ ├── vowel-recognition.cpp │ └── welcome-to-online-programming-1.c ├── HackerRank │ ├── APersonalizedEcho.sh │ ├── AfricanCities.sql │ ├── AngryProfessor.kt │ ├── AppleAndOrange.ts │ ├── ArmyGame.kt │ ├── AveragePopulation.sql │ ├── AveragePopulationOfEachContinent.sql │ ├── BalancedString.java │ ├── BeautifulBinaryString.kt │ ├── BeautifulDaysAtTheMovies.kt │ ├── BestDivisor.kt │ ├── BetweenTwoSets.kt │ ├── BillDivision.kt │ ├── BirthdayCakeCandles.js │ ├── BirthdayCakeCandles.ts │ ├── BreakingTheRecords.ts │ ├── CaesarCipher.kt │ ├── CamelCase.kt │ ├── CatsAndAMouse.kt │ ├── CircularArrayRotation.kt │ ├── Comparator.java │ ├── CountingValleys.kt │ ├── CutTheSticks.kt │ ├── CuttingPaperSquares.kt │ ├── DayOfTheProgrammer.kt │ ├── DesignerPdfViewer.kt │ ├── DivisibleSumPairs.ts │ ├── DrawingBook1.kt │ ├── DrawingBook2.kt │ ├── ElectronicsShop.kt │ ├── EmployeeNames.sql │ ├── EmployeeSalaries.sql │ ├── EqualizeTheArray.kt │ ├── ExtraLongFactorials.kt │ ├── FindDigits.kt │ ├── FizzBuzz.cpp │ ├── FunnyString.kt │ ├── GradingStudents.ts │ ├── HackerRankInString.kt │ ├── HalloweenParty.kt │ ├── Handshake.kt │ ├── IntroToTutorialChallenges.kt │ ├── IsFibo.kt │ ├── JapaneseCitiesAttributes.sql │ ├── JapaneseCitiesNames.sql │ ├── JumpingOnTheClouds.kt │ ├── JumpingOnTheCloudsRevisited.kt │ ├── LetsEcho.sh │ ├── LibraryFine.kt │ ├── LonelyInteger.kt │ ├── MarcsCakewalk.ts │ ├── MarkAndToys.kt │ ├── MarsExploration.kt │ ├── MatchingDigitsAndNonDigitCharacters.java │ ├── MatchingDigitsAndNonDigitCharacters.js │ ├── MatchingSpecificString.java │ ├── MatrixAddition.kt │ ├── MatrixMultiplication.kt │ ├── MatrixSubtraction.kt │ ├── MigratoryBirds.ts │ ├── MinimumHeightTriangle.kt │ ├── MissingNumbers.ts │ ├── ModifiedKaprekarNumbers.kt │ ├── NotesStore.js │ ├── NumberLineJumps.ts │ ├── Pangrams.kt │ ├── PermutationEquation.kt │ ├── PickingNumbers.kt │ ├── PointsOnALine.kt │ ├── README.md │ ├── React Skills Certification Test (HackerRank) │ │ ├── Q1 │ │ │ └── 74a81002-2956-4e21-a055-2768b9c03b8e │ │ │ │ ├── .gitignore │ │ │ │ ├── README.md │ │ │ │ ├── bin │ │ │ │ └── env_setup │ │ │ │ ├── package.json │ │ │ │ ├── public │ │ │ │ ├── index.html │ │ │ │ └── manifest.json │ │ │ │ └── src │ │ │ │ ├── App.css │ │ │ │ ├── App.js │ │ │ │ ├── App.test.js │ │ │ │ ├── components │ │ │ │ └── Slides.js │ │ │ │ ├── index.css │ │ │ │ ├── index.js │ │ │ │ ├── registerServiceWorker.js │ │ │ │ └── setupTests.js │ │ └── Q2 │ │ │ └── afaff9c8-2336-4dbc-a09c-1d3eaceabb53 │ │ │ ├── .gitignore │ │ │ ├── .jshintrc │ │ │ ├── README.md │ │ │ ├── package.json │ │ │ ├── public │ │ │ ├── index.html │ │ │ └── manifest.json │ │ │ └── src │ │ │ ├── App.css │ │ │ ├── App.js │ │ │ ├── App.test.js │ │ │ ├── components │ │ │ └── Articles.js │ │ │ ├── index.css │ │ │ ├── index.js │ │ │ └── registerServiceWorker.js │ ├── RectangularGame.kt │ ├── RemoveDuplicatesFromSortedArray.kt │ ├── RepeatedString.kt │ ├── RevisingAggregations.sql │ ├── RevisingAggregationsTheSumFunction.sql │ ├── RevisingTheSelectQueryI.sql │ ├── RevisingTheSelectQueryII.sql │ ├── SaveThePrisioner.kt │ ├── SecurityFunctions.kt │ ├── SelectAll.sql │ ├── SelectById.sql │ ├── SherlockAndDivisors.kt │ ├── SherlockAndPlanes.kt │ ├── SherlockAndSquares1.kt │ ├── SherlockAndSquares2.kt │ ├── StaffList.js │ ├── StrangeGridAgain.kt │ ├── SubarrayDivision.ts │ ├── TheHurdleRace.kt │ ├── TheLoveLetterMystery.kt │ ├── TimeConversion.ts │ ├── UtopianTree.kt │ ├── ViralAdvertising.kt │ ├── WeatherObservationStation1.sql │ ├── WeatherObservationStation10.sql │ ├── WeatherObservationStation11.sql │ ├── WeatherObservationStation12.sql │ ├── WeatherObservationStation13.sql │ ├── WeatherObservationStation14.sql │ ├── WeatherObservationStation15.sql │ ├── WeatherObservationStation16.sql │ ├── WeatherObservationStation17.sql │ ├── WeatherObservationStation3.sql │ ├── WeatherObservationStation4v1.sql │ ├── WeatherObservationStation4v2.sql │ ├── WeatherObservationStation5.sql │ ├── WeatherObservationStation6.sql │ ├── WeatherObservationStation7.sql │ ├── WeatherObservationStation8.sql │ ├── WeatherObservationStation9.sql │ ├── compareTriplets.py │ ├── diagonalDifference.c │ ├── miniMaxSum.cpp │ ├── plusMinus.c │ ├── plusMinus.py │ ├── roadRepair.cpp │ ├── simpleArraySum.c │ ├── simpleArraySum.js │ ├── simpleArraySum.py │ ├── sockMerchant.js │ ├── solveMeFirst.c │ ├── staircase.js │ ├── stringAnagram.cpp │ └── veryBigSum.java ├── Hash Code │ └── README.md ├── International Olympiad in Informatics │ └── README.md ├── Kattis │ ├── README.md │ ├── abc.cpp │ ├── abc_new.cpp │ └── hello.cpp ├── Kick Start │ └── README.md ├── LeetCode │ ├── BestTimeToBuyAndSellStock.kt │ ├── BuildArrayFromPermutation.kt │ ├── CombineTwoTables.sql │ ├── ConcatenationOfArray.kt │ ├── ConvertDateToBinary.kt │ ├── ConvertTheTemperature.kt │ ├── CountTheNumberOfConsistentStrings.kt │ ├── DefangingAnIPAddress.kt │ ├── DesignParkingSystemV1.kt │ ├── DesignParkingSystemV2.kt │ ├── DivisibleAndNonDivisibleSumsDifference.kt │ ├── EmployeeBonus.sql │ ├── EmployeesWithMissingInformation.sql │ ├── FindMinimumOperationToMakeAllDivisibleByThree.kt │ ├── FindTheMaximumAchievableX.kt │ ├── FindTotalTimeSpentByEachEmployee.sql │ ├── FindValueAfterOperations.kt │ ├── FindWordsContainingCharacter.kt │ ├── GoalParserInterpretationV1.kt │ ├── GoalParserInterpretationV2.kt │ ├── JewelsAndStones.kt │ ├── KidsWithGreatestNumberOfCandies.kt │ ├── MaximumNumberOfWordsFoundInSentences.kt │ ├── MinimumCommonValue.kt │ ├── MinimumNumberGame.kt │ ├── NumberOfGoodPairs.kt │ ├── NumberOfUniqueSubjectsTaughtByEachTeacher.sql │ ├── PalindromeNumber.kt │ ├── PermutationDifferenceBetweenTwoStrings.kt │ ├── ProjectEmployeesI.sql │ ├── README.md │ ├── RecyclableAndLowFatProducts.sql │ ├── RemoveElement.kt │ ├── RichestCustomerWealth.kt │ ├── RomanToInteger.kt │ ├── ScoreOfString.kt │ ├── SecondHighestSalary.sql │ ├── ShuffleTheArray.kt │ ├── TheTwoSneakyNumbersOfDigitvile.kt │ ├── UniqueNumberOfOccurrences.kt │ ├── reverseInteger.c │ └── twoSum.java ├── Neps Academy │ ├── AprovadoOuReprovado.cpp │ ├── AreaQuadrado.cpp │ ├── Bondinho.cpp │ ├── CampoMinado.cpp │ ├── CavernaDeOrdinskaya.cpp │ ├── Codigo.cpp │ ├── Consecutivos.cpp │ ├── ContagemDeAlgarismos.cpp │ ├── DroneDeEntrega.cpp │ ├── FaltaUma.cpp │ ├── Fibonacci.cpp │ ├── FitaColorida.cpp │ ├── Fliper.cpp │ ├── Formula 1.cpp │ ├── Fuga Com Helicoptero.cpp │ ├── Game10.cpp │ ├── Gangorra.cpp │ ├── Garcom.cpp │ ├── Gincana.cpp │ ├── Huaauhahhuahau.cpp │ ├── Lampadas.cpp │ ├── Matryoshka.cpp │ ├── Medalha.cpp │ ├── MediaInteira.cpp │ ├── OlaNepsAcademy.cpp │ ├── Olimpiadas.cpp │ ├── Operacoes.cpp │ ├── OrdenacaoSimples.cpp │ ├── ParOuImpar.cpp │ ├── PositivoNegativoNulo.cpp │ ├── PotenciaSimples.cpp │ ├── PremioDoMilhao.cpp │ ├── Primo.cpp │ ├── QuadradoMagico.cpp │ ├── README.md │ ├── Raizes.cpp │ ├── SomaFacil.cpp │ ├── SomaVetor.cpp │ ├── Teleferico.cpp │ ├── Titulo.cpp │ ├── TodosDivisores.cpp │ ├── Torre.cpp │ └── TorresDeHanoi.cpp ├── Olimpíada Brasileira de Informática │ ├── README.md │ ├── albumDeFotos.c │ ├── buscaNaInternet.c │ ├── buscaNaInternet.hs │ ├── cometa.c │ ├── corrida.c │ ├── pedagio.c │ ├── pneu.c │ ├── receitaDeBolo.c │ ├── somaDeCasas.c │ ├── tomadas.c │ └── xadrez.c ├── PKU JudgeOnline │ ├── A+B Problem.cpp │ └── README.md ├── Programmr │ ├── README.md │ └── sumOfDigits.cpp ├── Project Euler │ ├── README.md │ └── problem1.cpp ├── README.md ├── Sphere Online Judge │ ├── README.md │ └── lifeUniverseEverything.cpp ├── TechGig │ ├── README.md │ └── firstNfirst.cpp ├── Timus Online Judge │ ├── 1000 - A plus B.cpp │ └── README.md ├── TopCoder │ ├── README.md │ └── Sunshine.java ├── URI Online Judge │ ├── 1001 - Extremely Basic.c │ ├── 1001 - Extremely Basic.cpp │ ├── 1002 - Area of a Circle.c │ ├── 1002 - Area of a Circle.cpp │ ├── 1003 - Simple Sum.c │ ├── 1003 - Simple Sum.cpp │ ├── 1004 - Simple Product.c │ ├── 1004 - Simple Product.cpp │ ├── 1005 - Average 1.c │ ├── 1005 - Average 1.cpp │ ├── 1006 - Average 2.c │ ├── 1006 - Average 2.cpp │ ├── 1007 - Difference.c │ ├── 1007 - Difference.cpp │ ├── 1008 - Salary.c │ ├── 1008 - Salary.cpp │ ├── 1009 - Salary with Bonus.c │ ├── 1009 - Salary with Bonus.cpp │ ├── 1010 - Simple Calculate.c │ ├── 1010 - Simple Calculate.cpp │ ├── 1011 - Sphere.c │ ├── 1011 - Sphere.cpp │ ├── 1012 - Area.c │ ├── 1012 - Area.cpp │ ├── 1013 - The Greatest.c │ ├── 1013 - The Greatest.cpp │ ├── 1014 - Consumption.c │ ├── 1014 - Consumption.cpp │ ├── 1015 - Distance Between Two Points.c │ ├── 1015 - Distance Between Two Points.cpp │ ├── 1016 - Distance.c │ ├── 1016 - Distance.cpp │ ├── 1017 - Fuel Spent.c │ ├── 1017 - Fuel Spent.cpp │ ├── 1018 - Banknotes.c │ ├── 1018 - Banknotes.cpp │ ├── 1019 - Time Conversion.c │ ├── 1019 - Time Conversion.cpp │ ├── 1020 - Age in days.c │ ├── 1020 - Age in days.cpp │ ├── 1021 - Banknotes and Coins.c │ ├── 1021 - Banknotes and Coins.cpp │ ├── 1035 - Selection Test 1.cpp │ ├── 1036 - Bhaskara's Formula.cpp │ ├── 1037 - Interval.cpp │ ├── 1038 - Snack.cpp │ ├── 1042 - Simple Sort.cpp │ ├── 1047 - Game Time with Minutes.c │ ├── 1047 - Game Time with Minutes.cpp │ ├── 1059 - Even Number.cpp │ ├── 1065 - Even Between Five Numbers.cpp │ ├── 1070 - Six Odd Numbers.cpp │ ├── 1097 - Sequence IJ 3.cpp │ ├── 1115 - Quadrant.cpp │ ├── 1144 - Logical Sequence.cpp │ ├── 1153 - Simple Factorial.cpp │ ├── 1157 - Divisors I.cpp │ ├── 1161 - Factorial Sum.c │ ├── 1161 - Factorial Sum.cpp │ ├── 1176 - Fibonacci Array.cpp │ ├── 1221 - Fast Prime Number.cpp │ ├── 1253 - Caesar Cipher.c │ ├── 1253 - Caesar Cipher.cpp │ ├── 1557 - Square Matrix III.cpp │ ├── 1589 - Bob Conduit.cpp │ ├── 1602 - Hyperprimes.cpp │ ├── 1866 - Bill.cpp │ ├── 1924 - Vitoria and her indecision.cpp │ ├── 1930 - Electrical Outlet.cpp │ ├── 1933 - Tri-du.cpp │ ├── 1973 - Star Trek.cpp │ ├── 2006 - Identifying Tea.cpp │ ├── 2058 - Triangles and Regular Polygons.cpp │ ├── 2374 - Pneu.cpp │ ├── 2388 - Tacógrafo.cpp │ ├── 2413 - Busca na Internet.cpp │ ├── 2520 - The Last Analógimôn.cpp │ ├── 2544 - Kage Bunshin no Jutsu.cpp │ ├── 2615 - Expanding the Business.sql │ ├── 2670 - Máquina de Café.cpp │ ├── 2680 - Payroll.cpp │ ├── 2702 - Hard Choice.cpp │ ├── 2712 - Vehicular Restriction.cpp │ ├── 2718 - Christmas Lights.cpp │ ├── 2753 - Output7.cpp │ ├── 2787 - Chess.cpp │ ├── 2807 - Iccanobif.cpp │ ├── 2812 - Laércio.cpp │ ├── 2826 - Lexical.cpp │ ├── 2844 - Fast Writing, the Duel.cpp │ ├── 2846 - Fibonot.cpp │ ├── 2861 - The Output.cpp │ ├── 2936 - How Much Cassava.cpp │ ├── 2982 - The Strike Stops or Continue.cpp │ ├── 3053 - Jogo dos Copos.cpp │ ├── 3058 - Supermercado.cpp │ ├── 3084 - Old Clock.cpp │ └── README.md ├── UVa Online Judge │ ├── README.md │ └── the3timesNplus1Problem.cpp └── Zhejiang University Online Judge │ ├── 1000 - A plus B.cpp │ └── README.md └── Studies ├── AccumulateSTL.cpp ├── Arguments ├── README.md ├── numbers.txt └── numbers_sum.cpp ├── BinarySearchSTL.cpp ├── C++ Tutorial (W3Schools) ├── ClassesAccessSpecifiers.cpp ├── ClassesConstructors.cpp ├── ClassesConstructorsParameters.cpp ├── ClassesEncapsulation.cpp ├── ClassesInheritance1.cpp ├── ClassesInheritanceAccessSpecifiers.cpp ├── ClassesMethods1.cpp ├── ClassesMethodsParameters.cpp ├── ClassesMultilevelInheritance.cpp ├── ClassesMultipleInheritance.cpp ├── ClassesObjects1.cpp ├── ClassesOutsideConstructor.cpp ├── ClassesOutsideMethod1.cpp ├── ClassesPolymorphism.cpp ├── ExceptionExample1.cpp ├── ExceptionExample2.cpp ├── FilesCreateWrite.cpp ├── FilesRead.cpp ├── README.md └── filename.txt ├── Complexidade - NEPS ├── o_1.cpp ├── o_2n.cpp ├── o_fatn.cpp ├── o_logn.cpp ├── o_n.cpp ├── o_n2.cpp ├── o_nlogn.cpp └── o_sqrtn.cpp ├── DefineAndPair.cpp ├── Grafos (GEMP-CRT) ├── 1082_URI.py ├── 2666_URI.py ├── BFS.py ├── DFS.py └── MatrizDeAdjacencia.py ├── IotaSTL.cpp ├── JavaScript Algorithms (freeCodeCamp) ├── addTogether.js ├── binaryAgent.js ├── convertHTML.js ├── destroyer.js ├── diffArray.js ├── dropElements.js ├── fearNoLetter.js ├── makePerson.js ├── myReplace.js ├── orbitalPeriod.js ├── pairElement.js ├── smallestCommons.js ├── spinalCase.js ├── steamrollArray.js ├── sumAll.js ├── sumFibs.js ├── sumPrimes.js ├── translatePigLatin.js ├── truthCheck.js ├── uniteUnique.js └── whatIsInAName.js ├── JavaScript Projects (freeCodeCamp) ├── checkCashRegister.js ├── convertToRoman.js ├── palindrome.js ├── rot13.js └── telephoneCheck.js ├── MatrixJS.js ├── README.md ├── assert.cpp ├── bitOperation1.cpp ├── bitOperation2.cpp ├── defaultParameter.cpp ├── mathLib.cpp ├── mirrorProperty.cpp ├── myDict.py ├── overloading.cpp ├── palindrome.java ├── readLine.js ├── references.cpp ├── setPrecisionInline.cpp ├── swap.cpp └── use-recursion-to-create-a-range-of-numbers.js /Inspiring Codes/EmployeesWithMissingInformation.sql: -------------------------------------------------------------------------------- 1 | -- https://leetcode.com/problems/employees-with-missing-information/ 2 | 3 | SELECT employee_id 4 | FROM employees FULL JOIN salaries USING(employee_id) -- USING preserves employee_id in just one column. 5 | WHERE salary IS NULL OR name IS NULL -- Then, we can check the null fields. 6 | -------------------------------------------------------------------------------- /Inspiring Codes/README.md: -------------------------------------------------------------------------------- 1 | # Elegantly inspiring third-party codes 2 | 3 | Efficient approaches on problem solving. 4 | -------------------------------------------------------------------------------- /Inspiring Codes/countDigits.cpp: -------------------------------------------------------------------------------- 1 | // https://math.stackexchange.com/questions/231742/proof-how-many-digits-does-a-number-have-lfloor-log-10-n-rfloor-1 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | 10 | int n = 11111; 11 | 12 | cout << "Digits = " << floor(log10(n) + 1) << "\n"; 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Inspiring Codes/digitalRoot.c: -------------------------------------------------------------------------------- 1 | /* By: Unnamed, zoqdupt, monadius, whatmename, DarkD1 (plus 4 more warriors) @ Codewars */ 2 | 3 | /* Proof: https://proofwiki.org/wiki/Existence_of_Digital_Root */ 4 | 5 | #include 6 | 7 | int digital_root(int n); 8 | 9 | int main(){ 10 | 11 | int n=123; 12 | 13 | printf("%d\n", digital_root(n)); 14 | 15 | return 0; 16 | } 17 | 18 | int digital_root(int n) { 19 | 20 | return (n-1)%9 + 1; 21 | } 22 | -------------------------------------------------------------------------------- /Inspiring Codes/isAnagram.js: -------------------------------------------------------------------------------- 1 | /* https://algodaily.com/challenges/is-an-anagram */ 2 | 3 | function isAnagram(str1, str2) { 4 | 5 | if(str1.length!=str2.length) return false; 6 | 7 | var a = str1.toLowerCase(); 8 | var b = str2.toLowerCase(); 9 | 10 | a = a.split('').sort().join(''); 11 | b = b.split('').sort().join(''); 12 | 13 | return a === b; 14 | } 15 | 16 | console.log(isAnagram("Mary", "Army")) -------------------------------------------------------------------------------- /Inspiring Codes/maxLen.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBrito/competitive-programming/6779941f5ffff4fe5770826b1e4efdb6ca4a5d07/Inspiring Codes/maxLen.cpp -------------------------------------------------------------------------------- /Inspiring Codes/myConcat.java: -------------------------------------------------------------------------------- 1 | /* By: dcoles @ CodeSignal */ 2 | 3 | public class myConcat { 4 | 5 | public static void main(String[] args) { 6 | 7 | String[] strings = {"Code", "Fights", "On", "!"}; 8 | String separator = "/"; 9 | 10 | System.out.println(MyConcat(strings, separator)); 11 | } 12 | 13 | public static String MyConcat(String[] strings, String separator) { 14 | 15 | return separator.join(strings, separator) + separator; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Inspiring Codes/vowelRecognition.py: -------------------------------------------------------------------------------- 1 | # https://www.hackerearth.com/submission/28114856/ 2 | 3 | t = int(input()) 4 | 5 | v = ['a','e','i','o','u','A','E','I','O','U'] 6 | 7 | for _ in range(t): 8 | s = input() 9 | print(sum([(len(s)-i)*(i+1) for i in range(len(s)) if s[i] in v])) -------------------------------------------------------------------------------- /Solutions/Aizu Online Judge/0000 - QQ.cpp: -------------------------------------------------------------------------------- 1 | // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0000 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | for(int i=1; i<=9; i++){ 10 | 11 | for(int j=1; j<=9; j++){ 12 | 13 | cout << i << "x" << j << "=" << i*j << endl; 14 | } 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Solutions/Aizu Online Judge/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | http://judge.u-aizu.ac.jp/onlinejudge/user.jsp?id=danielbrito 4 | -------------------------------------------------------------------------------- /Solutions/AlgoDaily/README.md: -------------------------------------------------------------------------------- 1 | # Available at 2 | 3 | 4 | -------------------------------------------------------------------------------- /Solutions/AlgoDaily/intersection.js: -------------------------------------------------------------------------------- 1 | /* https://algodaily.com/challenges/array-intersection */ 2 | 3 | function intersection(nums1, nums2) { 4 | 5 | const set = new Set(nums1); 6 | const filteredSet = new Set(nums2.filter((n) => set.has(n))); 7 | 8 | return [...filteredSet]; 9 | } 10 | 11 | console.log(intersection([1,5,2,12,6,6],[13,10,9,5,8])); 12 | -------------------------------------------------------------------------------- /Solutions/AlgoDaily/isAnagram.js: -------------------------------------------------------------------------------- 1 | /* https://algodaily.com/challenges/is-an-anagram */ 2 | 3 | function isAnagram(str1, str2){ 4 | 5 | if(str1.length!=str2.length) return false; 6 | 7 | var x=0, y=0; 8 | 9 | str1.toLowerCase(); 10 | str2.toLowerCase(); 11 | 12 | for(var i=0; i=0; i--){ 8 | 9 | strRev += str[i]; 10 | } 11 | 12 | return strRev; 13 | } 14 | 15 | str = "daniel" 16 | 17 | console.log(reverseString(str)) 18 | -------------------------------------------------------------------------------- /Solutions/AtCoder/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | 4 | -------------------------------------------------------------------------------- /Solutions/AtCoder/taxiOrTrain.c: -------------------------------------------------------------------------------- 1 | /* https://atcoder.jp/contests/abc133/tasks/abc133_a */ 2 | 3 | #include 4 | 5 | int main(){ 6 | 7 | int N, A, B; 8 | 9 | scanf("%d %d %d", &N, &A, &B); 10 | 11 | N*A>B ? printf("%d\n", B) : printf("%d\n", N*A); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Solutions/AtCoder/taxiOrTrain.cpp: -------------------------------------------------------------------------------- 1 | /* https://atcoder.jp/contests/abc133/tasks/abc133_a */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int N, A, B; 10 | 11 | cin >> N >> A >> B; 12 | 13 | N*A>B ? cout << B << endl : cout << N*A << endl; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/CS Academy/Addition.cpp: -------------------------------------------------------------------------------- 1 | // https://csacademy.com/contest/archive/task/addition/ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int a, b; 10 | 11 | cin >> a >> b; 12 | 13 | cout << a + b; 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Solutions/CS Academy/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://csacademy.com/user/danielbrito 4 | -------------------------------------------------------------------------------- /Solutions/CSES/1083 - Missing Number.cpp: -------------------------------------------------------------------------------- 1 | // https://cses.fi/problemset/task/1083 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | long long int n, ap=0, sum=0, x; 10 | 11 | cin >> n; 12 | 13 | ap = (n*(1+n))/2; 14 | 15 | while(--n){ 16 | 17 | cin >> x; 18 | 19 | sum += x; 20 | } 21 | 22 | cout << ap-sum << "\n"; 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Solutions/CSES/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://cses.fi/user/14760 4 | -------------------------------------------------------------------------------- /Solutions/CheckiO/README.md: -------------------------------------------------------------------------------- 1 | # Profiles 2 | 3 | https://js.checkio.org/user/danielbrito/ \ 4 | https://py.checkio.org/user/danielbrito/ 5 | -------------------------------------------------------------------------------- /Solutions/CheckiO/multTwo.js: -------------------------------------------------------------------------------- 1 | /* https://js.checkio.org/mission/multiply-intro/ */ 2 | 3 | function multTwo(a, b) { 4 | return a*b; 5 | } 6 | 7 | console.log(multTwo(2,6)) -------------------------------------------------------------------------------- /Solutions/CheckiO/multTwo.py: -------------------------------------------------------------------------------- 1 | # https://py.checkio.org/mission/multiply-intro/ 2 | 3 | def mult_two(a: int, b: int) -> int: 4 | return a*b 5 | 6 | print(mult_two(2,3)) -------------------------------------------------------------------------------- /Solutions/CheckiO/multTwo.ts: -------------------------------------------------------------------------------- 1 | const assert = require('assert').strict; 2 | 3 | function multTwo(a: number, b: number): number { 4 | return a*b; 5 | } 6 | 7 | console.log('Example:'); 8 | console.log(multTwo(3, 2)); 9 | 10 | // These "asserts" are used for self-checking 11 | assert.equal(multTwo(3, 2), 6); 12 | assert.equal(multTwo(0, 1), 0); 13 | 14 | console.log("Coding complete? Click 'Check' to earn cool rewards!"); -------------------------------------------------------------------------------- /Solutions/CodCad/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | http://www.codcad.com/user/4341 -------------------------------------------------------------------------------- /Solutions/CodCad/division.cpp: -------------------------------------------------------------------------------- 1 | /* http://www.codcad.com/problem/3 */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | double A, B; 10 | 11 | cin >> A; 12 | cin >> B; 13 | 14 | cout.precision(2); 15 | cout.setf(ios::fixed); 16 | 17 | cout << A/B; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Solutions/CodCad/helloCodCad.cpp: -------------------------------------------------------------------------------- 1 | /* http://www.codcad.com/problem/1 */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | cout << "Ola CodCad!\n"; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Solutions/CodCad/plugs.cpp: -------------------------------------------------------------------------------- 1 | /* http://www.codcad.com/problem/11 */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int T1, T2, T3, T4; 10 | 11 | cin >> T1; 12 | cin >> T2; 13 | cin >> T3; 14 | cin >> T4; 15 | 16 | cout << T1+T2+T3+T4-3; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Solutions/CodCad/sum.cpp: -------------------------------------------------------------------------------- 1 | /* http://www.codcad.com/problem/2 */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int X, Y; 10 | 11 | cin >> X; 12 | cin >> Y; 13 | 14 | cout << X+Y; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Solutions/Code Jam/README.md: -------------------------------------------------------------------------------- 1 | # Available at 2 | 3 | 4 | -------------------------------------------------------------------------------- /Solutions/CodeChef/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://www.codechef.com/users/danielbrito -------------------------------------------------------------------------------- /Solutions/CodeSignal/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | https://codefights.com/profile/danielbrito 3 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/addTwoDigits.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* https://app.codesignal.com/arcade/code-arcade/intro-gates/wAGdN6FMPkx7WBq66 */ 4 | 5 | int addTwoDigits(int n) { 6 | 7 | return (n%10) + (n/10); 8 | } 9 | 10 | int main(){ 11 | 12 | int n=29; 13 | 14 | printf("%d", addTwoDigits(n)); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/addTwoDigits.cpp: -------------------------------------------------------------------------------- 1 | // https://app.codesignal.com/arcade/code-arcade/intro-gates/wAGdN6FMPkx7WBq66 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int addTwoDigits(int n) { 8 | 9 | return (n%10) + (n/10); 10 | } 11 | 12 | int main(){ 13 | 14 | int n=29; 15 | 16 | cout << addTwoDigits(n) << endl; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/alphabetSubsequence.cpp: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/Mi26C6CpxEs7yiDMo */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | bool alphabetSubsequence(string s); 8 | 9 | int main(){ 10 | 11 | string s = "aeb"; 12 | 13 | alphabetSubsequence(s) ? cout << "true\n" : cout << "false\n"; 14 | 15 | return 0; 16 | } 17 | 18 | bool alphabetSubsequence(string s) { 19 | 20 | int i=0; 21 | 22 | while(i=s[i+1]) return false; 25 | 26 | ++i; 27 | } 28 | 29 | return true; 30 | } 31 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/alphabetSubstring2.c: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/ptFrnXhzvADkCz5Ls */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | bool alphabetSubstring(char* s); 8 | 9 | int main(){ 10 | 11 | char string[20] = "efghi"; 12 | 13 | printf("%s\n", alphabetSubstring(string) ? "true" : "false"); 14 | 15 | return 0; 16 | } 17 | 18 | bool alphabetSubstring(char* s){ 19 | 20 | return strstr("abcdefghijklmnopqrstuvwxyz", s); 21 | } 22 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/alternatingSums.java: -------------------------------------------------------------------------------- 1 | /* https://codefights.com/arcade/intro/level-4/cC5QuL9fqvZjXJsW9 */ 2 | 3 | public class alternatingSums { 4 | 5 | public static void main(String[] args) { 6 | 7 | int[] a = {50, 60, 60, 45, 70}; 8 | int[] result = {0,0}; 9 | 10 | for(int i=0; i 4 | 5 | using namespace std; 6 | 7 | bool areSimilarNumbers(int a, int b, int divisor); 8 | 9 | int main(){ 10 | 11 | cout << (areSimilarNumbers(26, 7, 14) ? "true" : "false") << "\n"; 12 | 13 | return 0; 14 | } 15 | 16 | bool areSimilarNumbers(int a, int b, int divisor) { 17 | 18 | return (a%divisor==0 && b%divisor==0) || (a%divisor!=0 && b%divisor!=0); 19 | } 20 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/arrayElementsProduct.java: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/TuHac4M5746kwqTaH */ 2 | 3 | public class arrayElementsProduct { 4 | 5 | public static void main(String[] args) { 6 | 7 | int a[] = {1, 3, 2, 10}; 8 | 9 | System.out.println(ArrayElementsProduct(a)); 10 | } 11 | 12 | public static int ArrayElementsProduct(int[] a) { 13 | 14 | int r=1; 15 | 16 | for(int i=0; i 4 | 5 | int candies(int n, int m); 6 | 7 | int main(){ 8 | 9 | int n=3, m=10; 10 | 11 | printf("%d\n", candies(n, m)); 12 | 13 | return 0; 14 | } 15 | 16 | int candies(int n, int m){ 17 | 18 | return (m/n)*n; 19 | } 20 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/catWalk.py: -------------------------------------------------------------------------------- 1 | # https://app.codesignal.com/arcade/python-arcade/slithering-in-strings/GH7QauS4xyHin5YLm 2 | 3 | def catWalk(code): 4 | return " ".join(code.split()) 5 | 6 | print(catWalk("def m e gaDifficu ltFun ction(x):")) -------------------------------------------------------------------------------- /Solutions/CodeSignal/centuryForYear.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* https://codefights.com/arcade/intro/level-1/egbueTZRRL5Mm4TXN */ 5 | 6 | int centuryForYear(int year){ 7 | 8 | if(year%100==0){ 9 | 10 | return year/100; 11 | } 12 | else{ 13 | 14 | return (year/100) + 1; 15 | } 16 | } 17 | 18 | int main(){ 19 | 20 | int year; 21 | 22 | printf("Enter the year: "); 23 | scanf("%d", &year); 24 | 25 | printf("The century is %d\n", centuryForYear(year)); 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Solutions/CodeSignal/circleOfNumbers.c: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/arcade/code-arcade/intro-gates/vExYvcGnFsEYSt8nQ */ 2 | 3 | #include 4 | 5 | int circleOfNumbers(int n, int firstNumber); 6 | 7 | int main(){ 8 | 9 | int n=10, firstNumber=2; 10 | 11 | printf("%d\n", circleOfNumbers(n, firstNumber)); 12 | 13 | return 0; 14 | } 15 | 16 | int circleOfNumbers(int n, int firstNumber) { 17 | 18 | return firstNumber>=(n/2) ? firstNumber-(n/2) : firstNumber+(n/2); 19 | } 20 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/competitiveEating.py: -------------------------------------------------------------------------------- 1 | # https://app.codesignal.com/arcade/python-arcade/slithering-in-strings/BPFsda3ddPJruBX24 2 | 3 | # https://www.programiz.com/python-programming/methods/string/format 4 | 5 | def competitiveEating(t, width, precision): 6 | return '{:^{}.{}f}'.format(t, width, precision) 7 | 8 | print(competitiveEating(3.1415, 10, 2)) -------------------------------------------------------------------------------- /Solutions/CodeSignal/convertTabs.py: -------------------------------------------------------------------------------- 1 | # https://app.codesignal.com/arcade/python-arcade/slithering-in-strings/joYKtZyJDDsFQBLHP 2 | 3 | def convertTabs(code, x): 4 | return code.replace('\t', ' ' * x) 5 | 6 | print(convertTabs('\treturn False', 5)) -------------------------------------------------------------------------------- /Solutions/CodeSignal/countBits.py: -------------------------------------------------------------------------------- 1 | # https://app.codesignal.com/arcade/python-arcade/meet-python/7bGkfoFf65CiqbX3s */ 2 | 3 | def countBits(n): 4 | return n.bit_length() 5 | 6 | print(countBits(50)) -------------------------------------------------------------------------------- /Solutions/CodeSignal/countWaysToChangeDigit.c: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/YfXvndTvZuDcMbSFY */ 2 | 3 | #include 4 | 5 | int countWaysToChangeDigit(int n); 6 | 7 | int main(){ 8 | 9 | int n = 32310; 10 | 11 | printf("%d\n", countWaysToChangeDigit(n)); 12 | 13 | return 0; 14 | } 15 | 16 | int countWaysToChangeDigit(int n){ 17 | 18 | int count=0; 19 | 20 | while(n>0){ 21 | 22 | count += (9-n%10); 23 | n /= 10; 24 | } 25 | 26 | return count; 27 | } 28 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/evenDigitsOnly.c: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/nckaDwhQf2gb4HFhS */ 2 | 3 | #include 4 | #include 5 | 6 | bool evenDigitsOnly(int n); 7 | 8 | int main(){ 9 | 10 | int n = 64286; 11 | 12 | printf("%s\n", evenDigitsOnly(n)==true ? "True" : "False"); 13 | 14 | return 0; 15 | } 16 | 17 | bool evenDigitsOnly(int n) { 18 | 19 | while(n>0){ 20 | 21 | if(n%10%2==1) return 0; 22 | 23 | n /= 10; 24 | } 25 | 26 | return 1; 27 | } 28 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/evenDigitsOnlyRecursive.c: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/nckaDwhQf2gb4HFhS */ 2 | 3 | #include 4 | #include 5 | 6 | bool evenDigitsOnly(int n); 7 | 8 | int main(){ 9 | 10 | int n = 642386; 11 | 12 | printf("%s\n", evenDigitsOnly(n)==true ? "True" : "False"); 13 | 14 | return 0; 15 | } 16 | 17 | bool evenDigitsOnly(int n) { 18 | 19 | if(n%10%2==1) return 0; 20 | 21 | if(n<=9 && n%2==0) return 1; 22 | 23 | evenDigitsOnly(n/10); 24 | } 25 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/factorialTrailingZeros.c: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/jpaALgHRyNZCcuakt */ 2 | 3 | #include 4 | 5 | int factorialTrailingZeros(int n); 6 | 7 | int main(){ 8 | 9 | int n=20; 10 | 11 | printf("%d\n", factorialTrailingZeros(n)); 12 | 13 | return 0; 14 | } 15 | 16 | int factorialTrailingZeros(int n){ 17 | 18 | int i, c=0; 19 | 20 | for(i=5; n/i >= 1; i*=5){ 21 | 22 | c += n/i; 23 | } 24 | 25 | return c; 26 | } 27 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/feedbackReview.py: -------------------------------------------------------------------------------- 1 | # https://app.codesignal.com/arcade/python-arcade/slithering-in-strings/Rzf4YKMk69Jm3gNnm 2 | 3 | import textwrap 4 | 5 | def feedbackReview(feedback, size): 6 | return textwrap.wrap(feedback, size) 7 | 8 | print(feedbackReview("This is an example feedback", 8)) -------------------------------------------------------------------------------- /Solutions/CodeSignal/fibonacciNumber.c: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/hTvQiQuJTk9bSvY6n */ 2 | 3 | #include 4 | #include 5 | 6 | int fibonacciNumber(int n); 7 | 8 | int main(){ 9 | 10 | int n = 5; 11 | 12 | printf("%d\n", fibonacciNumber(n)); 13 | 14 | return 0; 15 | } 16 | 17 | int fibonacciNumber(int n) { 18 | 19 | float Fn; 20 | 21 | Fn = (pow(((1+sqrt(5))/2), n) - pow(((1-sqrt(5))/2), n)) / sqrt(5); // Binet's formula 22 | 23 | return (Fn>=0) ? (int)(Fn+0.5) : (int)(Fn-0.5); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/fixMessage.py: -------------------------------------------------------------------------------- 1 | # https://app.codesignal.com/arcade/python-arcade/slithering-in-strings/Wmdqw8NBzcbqHSsw7 2 | 3 | def fixMessage(message): 4 | return message.capitalize() 5 | 6 | print(fixMessage('daniel is VERY creative!')); -------------------------------------------------------------------------------- /Solutions/CodeSignal/getCommit.py: -------------------------------------------------------------------------------- 1 | # https://app.codesignal.com/arcade/python-arcade/slithering-in-strings/FmSEJMu8fbybQ7Ka4 2 | 3 | import re 4 | 5 | def getCommit(commit): 6 | return re.sub('[!+?0]', '', commit) 7 | 8 | print(getCommit("0??+0+!!someCommIdhsSt")) -------------------------------------------------------------------------------- /Solutions/CodeSignal/isCorrectSentence.c: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/xyg3gHjxeWJtqGDHz */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | bool isCorrectSentence(char* s) { 8 | 9 | return isupper(s[0]) && s[strlen(s)-1]=='.'; 10 | } 11 | 12 | int main(){ 13 | 14 | printf("%s\n", isCorrectSentence("This is a sentence.") ? "true" : "false"); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/isPrimeRecursive.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | bool isPrime(int n, int i); 5 | 6 | int main(){ 7 | 8 | int n = 18; 9 | 10 | printf("%d %s", n, isPrime(n, 2)==true ? "is prime\n" : "is not prime\n"); 11 | 12 | return 0; 13 | } 14 | 15 | bool isPrime(int n, int i){ 16 | 17 | if (n<=2) return (n==2) ? true : false; 18 | 19 | if (n%i==0) return false; 20 | 21 | if (i*i>n) return true; 22 | 23 | return isPrime(n, i+1); 24 | } 25 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/isWordPalindrome.py: -------------------------------------------------------------------------------- 1 | # https://app.codesignal.com/arcade/python-arcade/slithering-in-strings/r6xwnEjaw5kNgsyZD 2 | 3 | def isWordPalindrome(word): 4 | return word == word[::-1] 5 | 6 | print(isWordPalindrome('aibohphobia')) -------------------------------------------------------------------------------- /Solutions/CodeSignal/largestNumber.c: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/arcade/code-arcade/intro-gates/SZB5XypsMokGusDhX */ 2 | 3 | #include 4 | 5 | int largestNumber(int n); 6 | 7 | int main(){ 8 | 9 | int n; 10 | 11 | scanf("%d", &n); 12 | 13 | printf("%d\n", largestNumber(n)); 14 | 15 | return 0; 16 | } 17 | 18 | int largestNumber(int n) { 19 | 20 | int i, result=0; 21 | 22 | for(i=0; i 4 | 5 | int lastRide(int n); 6 | 7 | int main(){ 8 | 9 | int n = 240; 10 | 11 | printf("%d\n", lateRide(n)); 12 | 13 | return 0; 14 | } 15 | 16 | int lateRide(int n){ 17 | 18 | int r=0; 19 | 20 | n = (n/60)*100+n%60; 21 | 22 | while(n>0){ 23 | 24 | r += n%10; 25 | n /= 10; 26 | } 27 | 28 | return r; 29 | } 30 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/lateRide.cpp: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/arcade/code-arcade/intro-gates/aiKck9MwwAKyF8D4L */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int lastRide(int n); 8 | 9 | int main(){ 10 | 11 | int n = 240; 12 | 13 | printf("%d\n", lateRide(n)); 14 | 15 | return 0; 16 | } 17 | 18 | int lateRide(int n){ 19 | 20 | int r=0; 21 | 22 | n = (n/60)*100+n%60; 23 | 24 | while(n>0){ 25 | 26 | r += n%10; 27 | n /= 10; 28 | } 29 | 30 | return r; 31 | } -------------------------------------------------------------------------------- /Solutions/CodeSignal/lateRide.py: -------------------------------------------------------------------------------- 1 | # https://app.codesignal.com/challenge/zBehEvucW49je7bxr 2 | 3 | def lateRide(n): 4 | return sum(map(int, str((n//60)*100+(n%60)))) 5 | 6 | print(lateRide(808)) -------------------------------------------------------------------------------- /Solutions/CodeSignal/latinLettersSearchRegExp.c: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/hCr3bmQu9HewWjx4A */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | bool latinLettersSearchRegExp(char* s) { 9 | 10 | int i; 11 | 12 | for(i=0; i 4 | #include 5 | 6 | using namespace std; 7 | 8 | bool pointInLine(vector point, vector line); 9 | 10 | int main(){ 11 | 12 | vector point = {1, -1}; 13 | vector line = {1, 1, 0}; 14 | 15 | cout << (pointInLine(point, line) ? "true" : "false") << endl; 16 | 17 | return 0; 18 | } 19 | 20 | bool pointInLine(vector point, vector line) { 21 | 22 | return line[0]*point[0]+line[1]*point[1]+line[2]==0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/quasifactorial.c: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/53DMcWRBbZMdsF6vm */ 2 | 3 | #include 4 | 5 | int quasifactorial(int n); 6 | 7 | int main(){ 8 | 9 | int n = 4; 10 | 11 | printf("%d\n", quasifactorial(n)); 12 | 13 | return 0; 14 | } 15 | 16 | int quasifactorial(int n){ 17 | 18 | return n==1 ? 1 : n * quasifactorial(n-1) - 1; 19 | } 20 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/quasifactorial.cpp: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/53DMcWRBbZMdsF6vm */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int quasifactorial(int n); 8 | 9 | int main() { 10 | 11 | int n=4; 12 | cout << quasifactorial(n); 13 | 14 | return 0; 15 | } 16 | 17 | int quasifactorial(int n){ 18 | 19 | return n==1 ? 1 : n * quasifactorial(n-1) - 1; 20 | } 21 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/quasifactorial.hs: -------------------------------------------------------------------------------- 1 | -- https://app.codesignal.com/challenge/53DMcWRBbZMdsF6vm 2 | 3 | quasifactorial 1 = 1 4 | quasifactorial n = n * quasifactorial(n-1) - 1 5 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/quasifactorial.java: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/53DMcWRBbZMdsF6vm */ 2 | 3 | public class quasifactorial { 4 | 5 | public static void main(String[] args) { 6 | 7 | int n=4; 8 | 9 | System.out.println(Quasifactorial(n))); 10 | } 11 | 12 | public static int Quasifactorial(int n){ 13 | 14 | return n==1 ? 1 : n * Quasifactorial(n-1) - 1; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/quasifactorial.js: -------------------------------------------------------------------------------- 1 | // https://app.codesignal.com/challenge/53DMcWRBbZMdsF6vm 2 | 3 | function quasifactorial(n) { 4 | 5 | return n==1 ? 1 : n * quasifactorial(n-1) - 1; 6 | } 7 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/quasifactorial.py: -------------------------------------------------------------------------------- 1 | # https://app.codesignal.com/challenge/53DMcWRBbZMdsF6vm 2 | 3 | def quasifactorial(n): 4 | 5 | if n==1: 6 | return 1 7 | else: 8 | return n * quasifactorial(n-1) - 1 9 | 10 | print(quasifactorial(4)) 11 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/seatsInTheater.c: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/arcade/code-arcade/intro-gates/bszFiQAog96G9CXKg */ 2 | 3 | #include 4 | 5 | int seatsInTheater(int nCols, int nRows, int col, int row); 6 | 7 | int main(){ 8 | 9 | int nCols=16, nRows=11, col=5, row=3; 10 | 11 | printf("%d\n", seatsInTheater(nCols, nRows, col, row)); 12 | } 13 | 14 | int seatsInTheater(int nCols, int nRows, int col, int row) { 15 | 16 | return (nRows-row)*(nCols-col+1); 17 | } 18 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/shapeArea.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* https://codefights.com/arcade/intro/level-2/yuGuHvcCaFCKk56rJ */ 6 | 7 | int shapeArea(int n){ 8 | 9 | return pow(n, 2) + pow(n-1, 2); 10 | } 11 | 12 | int main(){ 13 | 14 | int number; 15 | 16 | printf("Enter a number: "); 17 | scanf("%d", &number); 18 | 19 | printf("Area of the polygon = %d\n", shapeArea(number)); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/simpleSort.py: -------------------------------------------------------------------------------- 1 | def simpleSort(arr): 2 | 3 | n = len(arr) 4 | 5 | for i in range(n): 6 | j = 0 7 | stop = n - i 8 | while j < stop - 1: 9 | if arr[j] > arr[j + 1]: 10 | aux = arr[j]; 11 | arr[j] = arr[j+1] 12 | arr[j+1] = aux; 13 | j += 1 14 | return arr -------------------------------------------------------------------------------- /Solutions/CodeSignal/squareColor.c: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/M2gCWoc9fFk5hgSQT */ 2 | 3 | #include 4 | #include 5 | 6 | bool squareColor(int x, int y, int x1, int y1); 7 | 8 | int main(){ 9 | 10 | int x, y, x1, y1; 11 | 12 | x=0; y=2; x1=5; y1=6; 13 | 14 | printf("%s\n", squareColor(x, y, x1, y1) ? "true" : "false"); 15 | 16 | return 0; 17 | } 18 | 19 | bool squareColor(int x, int y, int x1, int y1){ 20 | 21 | return abs((abs(x-y)-(abs(x1-y1))))%2==1 ? false : true; 22 | } 23 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/sum.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* https://codefights.com/arcade/intro/level-1/jwr339Kq6e3LQTsfa */ 5 | 6 | int add(int param1, int param2) { 7 | 8 | return param1 + param2; 9 | } 10 | 11 | int main(){ 12 | 13 | int num1, num2; 14 | 15 | printf("Enter the first number: "); 16 | scanf("%d", &num1); 17 | 18 | printf("Enter the second number: "); 19 | scanf("%d", &num2); 20 | 21 | printf("\n%d + %d = %d\n", num1, num2, add(num1, num2)); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/whoseMove.cpp: -------------------------------------------------------------------------------- 1 | /* https://app.codesignal.com/challenge/R6pswKNcG8iW4H4Rf */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | string whoseMove(string lastPlayer, bool win); 8 | 9 | int main(){ 10 | 11 | string lastPlayer = "black"; 12 | bool win = false; 13 | 14 | cout << whoseMove(lastPlayer, win) << "\n"; 15 | 16 | return 0; 17 | } 18 | 19 | string whoseMove(string lastPlayer, bool win) { 20 | 21 | return win ? lastPlayer : lastPlayer.compare("white")==0 ? "black" : "white"; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Solutions/CodeSignal/zigzagTriple.kt: -------------------------------------------------------------------------------- 1 | fun solution(numbers: MutableList): MutableList { 2 | val solution = mutableListOf() 3 | 4 | for(i in 0 until numbers.size - 2) { 5 | if((numbers[i] < numbers[i + 1] && numbers[i + 1] > numbers[i + 2]) || (numbers[i] > numbers[i + 1] && numbers[i + 1] < numbers[i + 2])) { 6 | solution.add(1) 7 | } else { 8 | solution.add(0) 9 | } 10 | } 11 | 12 | return solution 13 | } 14 | -------------------------------------------------------------------------------- /Solutions/Codeforces/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | 4 | -------------------------------------------------------------------------------- /Solutions/Codeforces/aHulk.c: -------------------------------------------------------------------------------- 1 | /* https://codeforces.com/problemset/problem/705/A */ 2 | 3 | #include 4 | 5 | int main(){ 6 | 7 | int n, i; 8 | 9 | scanf("%d", &n); 10 | 11 | for(i=1; i<=n; i++){ 12 | 13 | if(i 4 | 5 | int main(){ 6 | 7 | int n, k; 8 | 9 | scanf("%d %d", &n, &k); 10 | 11 | while(k--){ 12 | 13 | n = n%10>=1 ? n-1 : n/10; 14 | } 15 | 16 | printf("%d\n", n); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Solutions/Coderbyte/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://coderbyte.com/profile/danielbrito -------------------------------------------------------------------------------- /Solutions/Coderbyte/firstFactorial.c: -------------------------------------------------------------------------------- 1 | /* https://coderbyte.com/information/First%20Factorial */ 2 | 3 | #include 4 | #include 5 | 6 | void FirstFactorial(int num[]) { 7 | 8 | int r=1, i; 9 | 10 | for(i=1; i<=num; i++){ 11 | 12 | r *= i; 13 | } 14 | 15 | printf("%d\n", r); 16 | } 17 | 18 | int main(void) { 19 | 20 | // keep this function call here 21 | FirstFactorial(gets(stdin)); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Solutions/Codewars/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://www.codewars.com/users/danielbrito 4 | -------------------------------------------------------------------------------- /Solutions/Codewars/digitalRoot.cpp: -------------------------------------------------------------------------------- 1 | /* https://www.codewars.com/kata/541c8630095125aba6000c00/train/cpp */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int digitalRoot(int n){ 8 | 9 | while (n >= 10) { 10 | 11 | int sum = 0; 12 | 13 | while (n > 0) { 14 | 15 | sum += n%10; 16 | n = n/10; 17 | } 18 | 19 | n = sum; 20 | } 21 | 22 | return n; 23 | } 24 | 25 | int main(){ 26 | 27 | int n = 12345; 28 | 29 | cout << digitalRoot(n) << "\n"; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Solutions/Codewars/digitalRootRecursive.c: -------------------------------------------------------------------------------- 1 | /* https://www.codewars.com/kata/sum-of-digits-slash-digital-root/c */ 2 | 3 | #include 4 | 5 | int digitalRoot(int n); 6 | 7 | int main(){ 8 | 9 | int n=132189; 10 | 11 | printf("%d\n", digitalRoot(n)); 12 | 13 | return 0; 14 | } 15 | 16 | int digitalRoot(int n){ 17 | 18 | return n>9 ? digitalRoot(n%10+n/10) : n; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Solutions/Codewars/setAlarm.c: -------------------------------------------------------------------------------- 1 | /* https://www.codewars.com/kata/l1-set-alarm/c */ 2 | 3 | #include 4 | #include 5 | 6 | bool set_alarm(bool employed, bool vacation) { 7 | 8 | return employed==vacation ? false : employed ? true : false; 9 | } 10 | 11 | int main(){ 12 | 13 | bool employed = true; 14 | bool vacation = false; 15 | 16 | printf(set_alarm(employed, vacation) ? "true\n" : "false\n"); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Solutions/Codingame/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://www.codingame.com/profile/f9d3bed50b18546c0f354ba7926809739222323 4 | -------------------------------------------------------------------------------- /Solutions/DWITE/README.md: -------------------------------------------------------------------------------- 1 | # Available at 2 | 3 | 4 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-08/README.md: -------------------------------------------------------------------------------- 1 | # Problem: 08-Jul-2019 2 | 3 | This problem was recently asked by Google. 4 | 5 | Given a list of numbers and a number ```k```, return whether any two numbers from the list add up to ```k```. 6 | For example, given ```[10, 15, 3, 7]``` and ```k``` of ```17```, return true since ```10 + 7``` is ```17```. 7 | 8 | Bonus: Can you do this in one pass? 9 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-09/README.md: -------------------------------------------------------------------------------- 1 | # Problem: 2019-07-09 2 | 3 | This problem was asked by Uber. 4 | 5 | Given an array of integers, return a new array such that each element at index ```i``` of the new array is the product of all the numbers in the original array except the one at ```i```. 6 | For example, if our input was ```[1, 2, 3, 4, 5]```, the expected output would be ```[120, 60, 40, 30, 24]```. If our input was ```[3, 2, 1]```, the expected output would be ```[2, 3, 6]```. 7 | 8 | Follow-up: what if you can't use division? 9 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-11/README.md: -------------------------------------------------------------------------------- 1 | # Problem 11-07-2019 2 | 3 | This problem was asked by Stripe. 4 | 5 | Given an array of integers, find the first missing positive integer in linear time and constant space. In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well. 6 | 7 | For example, the input ```[3, 4, -1, 1]``` should give ```2```. The input ```[1, 2, 0]``` should give ```3```. 8 | 9 | You can modify the input array in-place. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-12/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | 3 | public static void main(String[] args) { 4 | 5 | System.out.println(Pair.car(Pair.cons(3, 4))); 6 | System.out.println(Pair.cdr(Pair.cons(3, 4))); 7 | } 8 | } -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-12/Pair.java: -------------------------------------------------------------------------------- 1 | public class Pair { 2 | 3 | int a; 4 | int b; 5 | 6 | public Pair(int a, int b) { 7 | 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | public static Pair cons(int a, int b) { 13 | 14 | return new Pair(a, b); 15 | } 16 | 17 | public static int car(Pair p) { 18 | 19 | return p.a; 20 | } 21 | 22 | public static int cdr(Pair p) { 23 | 24 | return p.b; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-12/README.md: -------------------------------------------------------------------------------- 1 | # Problem 12-07-2019 2 | 3 | This problem was asked by Jane Street. 4 | 5 | ```cons(a, b)``` constructs a pair, and ```car(pair)``` and ```cdr(pair)``` returns the first and last element of that pair. For example, ```car(cons(3, 4))``` returns ```3```, and ```cdr(cons(3, 4))``` returns ```4```. 6 | 7 | Given this implementation of cons: 8 | 9 | ``` 10 | def cons(a, b): 11 | def pair(f): 12 | return f(a, b) 13 | return pair 14 | ``` 15 | 16 | Implement ```car``` and ```cdr```. 17 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-14/README.md: -------------------------------------------------------------------------------- 1 | # Problem 14-07-2019 (TO-DO) 2 | 3 | This problem was asked by Facebook. 4 | 5 | Given the mapping ```a = 1, b = 2, ... z = 26```, and an encoded message, count the number of ways it can be decoded. 6 | For example, the message ```'111'``` would give ```3```, since it could be decoded as ```'aaa', 'ka', and 'ak'```. 7 | 8 | You can assume that the messages are decodable. For example, ```'001'``` is not allowed. 9 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-15/README.md: -------------------------------------------------------------------------------- 1 | # Problem 15-07-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | A unival tree (which stands for "universal value") is a tree where all nodes under it have the same value. 6 | 7 | Given the root to a binary tree, count the number of unival subtrees. 8 | 9 | For example, the following tree has ```5``` unival subtrees: 10 | 11 | ``` 12 | 0 13 | / \ 14 | 1 0 15 | / \ 16 | 1 0 17 | / \ 18 | 1 1 19 | ``` 20 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-16/README.md: -------------------------------------------------------------------------------- 1 | # Problem 16-07-2019 (TO-DO) 2 | 3 | This problem was asked by Airbnb. 4 | 5 | Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. Numbers can be ```0``` or negative. 6 | 7 | For example, ```[2, 4, 6, 2, 5]``` should return ```13```, since we pick ```2```, ```6```, and ```5```. ```[5, 1, 1, 5]``` should return ```10```, since we pick ```5``` and ```5```. 8 | 9 | Follow-up: Can you do this in O(N) time and constant space? 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-17/README.md: -------------------------------------------------------------------------------- 1 | # Problem 17-07-2019 (TO-DO) 2 | 3 | This problem was asked by Apple. 4 | 5 | Implement a job scheduler which takes in a function ```f``` and an integer ```n```, and calls ```f``` after ```n``` milliseconds. 6 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-18/README.md: -------------------------------------------------------------------------------- 1 | # Problem 18-07-2019 (TO-DO) 2 | 3 | This problem was asked by Twitter. 4 | 5 | Implement an autocomplete system. That is, given a query string ```s``` and a set of all possible query strings, return all strings in the set that have ```s``` as a prefix. 6 | 7 | For example, given the query string ```de``` and the set of strings ```[dog, deer, deal]```, return ```[deer, deal]```. 8 | 9 | Hint: Try preprocessing the dictionary into a more efficient data structure to speed up queries. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-20/README.md: -------------------------------------------------------------------------------- 1 | # Problem 20-07-2019 (TO-DO) 2 | 3 | This problem was asked by Amazon. 4 | 5 | Given an integer ```k``` and a string ```s```, find the length of the longest substring that contains at most ```k``` distinct characters. 6 | 7 | For example, given ```s = "abcba"``` and ```k = 2```, the longest substring with ```k``` distinct characters is ```"bcb"```. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-21/README.md: -------------------------------------------------------------------------------- 1 | # Problem 21-07-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | The area of a circle is defined as ```πr^2```. Estimate ```π``` to ```3``` decimal places using a Monte Carlo method. 6 | 7 | Hint: The basic equation of a circle is x^2 + y^2 = r^2. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-22/README.md: -------------------------------------------------------------------------------- 1 | # Problem 22-07-2019 (TO-DO) 2 | 3 | This problem was asked by Facebook. 4 | 5 | Given a stream of elements too large to store in memory, pick a random element from the stream with uniform probability. 6 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-23/README.md: -------------------------------------------------------------------------------- 1 | # Problem 23-07-2019 (TO-DO) 2 | 3 | This problem was asked by Twitter. 4 | 5 | You run an e-commerce website and want to record the last N order ids in a log. Implement a data structure to accomplish this, with the following API: 6 | 7 | * record(order_id): adds the order_id to the log 8 | * get_last(i): gets the ith last element from the log. i is guaranteed to be smaller than or equal to N. 9 | 10 | You should be as efficient with time and space as possible. 11 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-26/README.md: -------------------------------------------------------------------------------- 1 | # Problem 26-07-2019 (TO-DO) 2 | 3 | This problem was asked by Facebook. 4 | 5 | A builder is looking to build a row of N houses that can be of K different colors. He has a goal of minimizing cost while ensuring that no two neighboring houses are of the same color. 6 | 7 | Given an N by K matrix where the nth row and kth column represents the cost to build the nth house with kth color, return the minimum cost which achieves this goal. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-27/README.md: -------------------------------------------------------------------------------- 1 | # Problem 27-07-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | Given two singly linked lists that intersect at some point, find the intersecting node. The lists are non-cyclical. 6 | 7 | For example, given A = 3 -> 7 -> 8 -> 10 and B = 99 -> 1 -> 8 -> 10, return the node with value 8. 8 | 9 | In this example, assume nodes with the same value are the exact same node objects. 10 | 11 | Do this in O(M + N) time (where M and N are the lengths of the lists) and constant space. 12 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-07-28/README.md: -------------------------------------------------------------------------------- 1 | # Problem 28-07-2019 (TO-DO) 2 | 3 | This problem was asked by Snapchat. 4 | 5 | Given an array of time intervals (start, end) for classroom lectures (possibly overlapping), find the minimum number of rooms required. 6 | 7 | For example, given [(30, 75), (0, 50), (60, 150)], you should return 2. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-02/README.md: -------------------------------------------------------------------------------- 1 | # Problem 02-08-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | Given a singly linked list and an integer ```k```, remove the kth last element from the list. ```k``` is guaranteed to be smaller than the length of the list. 6 | 7 | The list is very long, so making more than one pass is prohibitively expensive. 8 | 9 | Do this in constant space and in one pass. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-03/README.md: -------------------------------------------------------------------------------- 1 | # Problem 03-08-2019 (TO-DO) 2 | 3 | This problem was asked by Facebook. 4 | 5 | Given a string of round, curly, and square open and closing brackets, return whether the brackets are balanced (well-formed). 6 | 7 | For example, given the string "([])[]({})", you should return true. 8 | 9 | Given the string "([)]" or "((()", you should return false. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-05/README.md: -------------------------------------------------------------------------------- 1 | # Problem 05-08-2019 (TO-DO) 2 | 3 | This problem was asked by Amazon. 4 | 5 | Run-length encoding is a fast and simple method of encoding strings. The basic idea is to represent repeated successive characters as a single count and character. For example, the string "AAAABBBCCDAA" would be encoded as "4A3B2C1D2A". 6 | 7 | Implement run-length encoding and decoding. You can assume the string to be encoded have no digits and consists solely of alphabetic characters. You can assume the string to be decoded is valid. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-07/README.md: -------------------------------------------------------------------------------- 1 | # Problem 07-08-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | The edit distance between two strings refers to the minimum number of character insertions, deletions, and substitutions required to change one string to the other. For example, the edit distance between “kitten” and “sitting” is three: substitute the “k” for “s”, substitute the “e” for “i”, and append a “g”. 6 | 7 | Given two strings, compute the edit distance between them. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-08/README.md: -------------------------------------------------------------------------------- 1 | # Problem 08-08-2019 (TO-DO) 2 | 3 | This problem was asked by Jane Street. 4 | 5 | Suppose you are given a table of currency exchange rates, represented as a 2D array. Determine whether there is a possible arbitrage: that is, whether there is some sequence of trades you can make, starting with some amount A of any currency, so that you can end up with some amount greater than A of that currency. 6 | 7 | There are no transaction costs and you can trade fractional quantities. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-09/README.md: -------------------------------------------------------------------------------- 1 | # Problem 09-08-2019 (TO-DO) 2 | 3 | This problem was asked by Microsoft. 4 | 5 | Compute the running median of a sequence of numbers. That is, given a stream of numbers, print out the median of the list so far on each new element. 6 | 7 | Recall that the median of an even-numbered list is the average of the two middle numbers. 8 | 9 | For example, given the sequence [2, 1, 5, 7, 2, 0, 5], your algorithm should print out: 10 | 11 | ``` 12 | 2 13 | 1.5 14 | 2 15 | 3.5 16 | 2 17 | 2 18 | 2 19 | ``` 20 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-11/README.md: -------------------------------------------------------------------------------- 1 | # Problem 11-08-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | Given an array of strictly the characters 'R', 'G', and 'B', segregate the values of the array so that all the Rs come first, the Gs come second, and the Bs come last. You can only swap elements of the array. 6 | 7 | Do this in linear time and in-place. 8 | 9 | For example, given the array ['G', 'B', 'R', 'R', 'B', 'R', 'G'], it should become ['R', 'R', 'R', 'G', 'G', 'B', 'B']. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-12/README.md: -------------------------------------------------------------------------------- 1 | # Problem 12-08-2019 (TO-DO) 2 | 3 | This problem was asked by Dropbox. 4 | 5 | Given the root to a binary search tree, find the second largest node in the tree. 6 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-13/README.md: -------------------------------------------------------------------------------- 1 | # Problem 13-08-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | The power set of a set is the set of all its subsets. Write a function that, given a set, generates its power set. 6 | 7 | For example, given the set ```{1, 2, 3}```, it should return ```{{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}```. 8 | 9 | You may also use a list or array to represent a set. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-14/README.md: -------------------------------------------------------------------------------- 1 | # Problem 15-08-2019 (TO-DO) 2 | 3 | This problem was asked by Microsoft. 4 | 5 | You have an N by N board. Write a function that, given N, returns the number of possible arrangements of the board where N queens can be placed on the board without threatening each other, i.e. no two queens share the same row, column, or diagonal. 6 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-16/README.md: -------------------------------------------------------------------------------- 1 | # Problem 16-08-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | Given an array of integers where every integer occurs three times except for one integer, which only occurs once, find and return the non-duplicated integer. 6 | 7 | For example, given [6, 1, 3, 3, 3, 6, 6], return 1. Given [13, 19, 13, 13], return 19. 8 | 9 | Do this in O(N) time and O(1) space. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-18/README.md: -------------------------------------------------------------------------------- 1 | # Problem 18-08-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | Given a list of integers S and a target number k, write a function that returns a subset of S that adds up to k. If such a subset cannot be made, then return null. 6 | 7 | Integers can appear more than once in the list. You may assume all numbers in the list are positive. 8 | 9 | For example, given S = [12, 1, 61, 5, 9, 2] and k = 24, return [12, 9, 2, 1] since it sums up to 24. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-21/README.md: -------------------------------------------------------------------------------- 1 | # Problem 21-08-2019 (TO-DO) 2 | 3 | This problem was asked by Two Sigma. 4 | 5 | Using a function ```rand5()``` that returns an integer from 1 to 5 (inclusive) with uniform probability, implement a function ```rand7()``` that returns an integer from 1 to 7 (inclusive). 6 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-22/README.md: -------------------------------------------------------------------------------- 1 | # Problem 22-08-2019 (TO-DO) 2 | 3 | This problem was asked by Amazon. 4 | 5 | Given a string, find the longest palindromic contiguous substring. If there are more than one with the maximum length, return any one. 6 | 7 | For example, the longest palindromic substring of "aabcdcb" is "bcdcb". The longest palindromic substring of "bananas" is "anana". 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-23/README.md: -------------------------------------------------------------------------------- 1 | # Problem 23-08-2019 (TO-DO) 2 | 3 | This problem was asked by Facebook. 4 | 5 | Given a array of numbers representing the stock prices of a company in chronological order, write a function that calculates the maximum profit you could have made from buying and selling that stock once. You must buy before you can sell it. 6 | 7 | For example, given [9, 11, 8, 5, 7, 10], you should return 5, since you could buy the stock at 5 dollars and sell it at 10 dollars. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-24/README.md: -------------------------------------------------------------------------------- 1 | # Problem 24-08-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | Given pre-order and in-order traversals of a binary tree, write a function to reconstruct the tree. 6 | 7 | For example, given the following preorder traversal: 8 | 9 | [a, b, d, e, c, f, g] 10 | 11 | And the following inorder traversal: 12 | 13 | [d, b, e, a, f, c, g] 14 | 15 | You should return the following tree: 16 | 17 | ``` 18 | a 19 | / \ 20 | b c 21 | / \ / \ 22 | d e f g 23 | ``` 24 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-25/README.md: -------------------------------------------------------------------------------- 1 | # Problem 25-08-2019 (TO-DO) 2 | 3 | This problem was asked by Amazon. 4 | 5 | Given an array of numbers, find the maximum sum of any contiguous subarray of the array. 6 | 7 | For example, given the array [34, -50, 42, 14, -5, 86], the maximum sum would be 137, since we would take elements 42, 14, -5, and 86. 8 | 9 | Given the array [-5, -1, -8, -9], the maximum sum would be 0, since we would not take any elements. 10 | 11 | Do this in O(N) time. 12 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-27/README.md: -------------------------------------------------------------------------------- 1 | # Problem 27-08-2019 (TO-DO) 2 | 3 | This problem was asked by Facebook. 4 | 5 | Given a function that generates perfectly random numbers between 1 and k (inclusive), where k is an input, write a function that shuffles a deck of cards represented as an array using only swaps. 6 | 7 | It should run in O(N) time. 8 | 9 | Hint: Make sure each one of the 52! permutations of the deck is equally likely. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-29/README.md: -------------------------------------------------------------------------------- 1 | # Problem 29-08-2019 (TO-DO) 2 | 3 | This problem was asked by Apple. 4 | 5 | Implement a queue using two stacks. Recall that a queue is a FIFO (first-in, first-out) data structure with the following methods: enqueue, which inserts an element into the queue, and dequeue, which removes it. 6 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-30/README.md: -------------------------------------------------------------------------------- 1 | # Problem 30-08-2019 (TO-DO) 2 | 3 | This problem was asked by Dropbox. 4 | 5 | Sudoku is a puzzle where you're given a partially-filled 9 by 9 grid with digits. The objective is to fill the grid with the constraint that every row, column, and box (3 by 3 subgrid) must contain all of the digits from 1 to 9. 6 | 7 | Implement an efficient sudoku solver. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-08-31/README.md: -------------------------------------------------------------------------------- 1 | # Problem 31-08-2019 (TO-DO) 2 | 3 | This problem was asked by Microsoft. 4 | 5 | Implement a URL shortener with the following methods: 6 | 7 | * ```shorten(url)```, which shortens the url into a six-character alphanumeric string, such as ```zLg6wl```. 8 | * ```restore(short)```, which expands the shortened string into the original url. If no such shortened string exists, return null. 9 | 10 | Hint: What if we enter the same URL twice? 11 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-01/README.md: -------------------------------------------------------------------------------- 1 | # Problem 01-09-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | Given an undirected graph represented as an adjacency matrix and an integer k, write a function to determine whether each vertex in the graph can be colored such that no two adjacent vertices share the same color using at most k colors. 6 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-03/README.md: -------------------------------------------------------------------------------- 1 | # Problem 03-09-2019 (TO-DO) 2 | 3 | This problem was asked by Amazon. 4 | 5 | An sorted array of integers was rotated an unknown number of times. 6 | 7 | Given such an array, find the index of the element in the array in faster than linear time. If the element doesn't exist in the array, return null. 8 | 9 | For example, given the array [13, 18, 25, 2, 8, 10] and the element 8, return 4 (the index of 8 in the array). 10 | 11 | You can assume all the integers in the array are unique. 12 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-04/README.md: -------------------------------------------------------------------------------- 1 | # Problem 04-09-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | Implement a file syncing algorithm for two computers over a low-bandwidth network. What if we know the files in the two computers are mostly the same? 6 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-06/README.md: -------------------------------------------------------------------------------- 1 | # Problem 06-09-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | Implement integer exponentiation. That is, implement the ```pow(x, y)``` function, where ```x``` and ```y``` are integers and returns ```x^y```. 6 | 7 | Do this faster than the naive method of repeated multiplication. 8 | 9 | For example, ```pow(2, 10)``` should return ```1024```. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-09/README.md: -------------------------------------------------------------------------------- 1 | # Problem 09-09-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | A knight's tour is a sequence of moves by a knight on a chessboard such that all squares are visited once. 6 | 7 | Given N, write a function to return the number of knight's tours on an N by N chessboard. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-11/README.md: -------------------------------------------------------------------------------- 1 | # Problem 11-09-2019 (TO-DO) 2 | 3 | This problem was asked by Square. 4 | 5 | Assume you have access to a function ```toss_biased()``` which returns 0 or 1 with a probability that's not 50-50 (but also not 0-100 or 100-0). You do not know the bias of the coin. 6 | 7 | Write a function to simulate an unbiased coin toss. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-14/README.md: -------------------------------------------------------------------------------- 1 | # Problem 14-09-2019 (TO-DO) 2 | 3 | This problem was asked by Facebook. 4 | 5 | Given a list of integers, return the largest product that can be made by multiplying any three integers. 6 | 7 | For example, if the list is ```[-10, -10, 5, 2]```, we should return ```500```, since that's ```-10 * -10 * 5```. 8 | 9 | You can assume the list has at least three integers. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-15/README.md: -------------------------------------------------------------------------------- 1 | # Problem 15-09-2019 (TO-DO) 2 | 3 | This problem was asked by Microsoft. 4 | 5 | A number is considered perfect if its digits sum up to exactly 10. 6 | 7 | Given a positive integer ```n```, return the ```n```-th perfect number. 8 | 9 | For example, given 1, you should return 19. Given 2, you should return 28. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-16/README.md: -------------------------------------------------------------------------------- 1 | # Problem 16-09-2019 (TO-DO) 2 | 3 | This problem was asked by Two Sigma. 4 | 5 | Using a function ```rand7()``` that returns an integer from 1 to 7 (inclusive) with uniform probability, implement a function ```rand5()``` that returns an integer from 1 to 5 (inclusive). 6 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-18/README.md: -------------------------------------------------------------------------------- 1 | # Problem 18-09-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | Given the head of a singly linked list, reverse it in-place. 6 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-20/README.md: -------------------------------------------------------------------------------- 1 | # Problem 20-09-2019 (TO-DO) 2 | 3 | This problem was asked by Microsoft. 4 | 5 | Given an array of numbers, find the length of the longest increasing subsequence in the array. The subsequence does not necessarily have to be contiguous. 6 | 7 | For example, given the array [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15], the longest increasing subsequence has length 6: it is 0, 2, 6, 9, 11, 15. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-22/README.md: -------------------------------------------------------------------------------- 1 | # Problem 22-09-2019 (TO-DO) 2 | 3 | This problem was asked by Snapchat. 4 | 5 | Given a list of possibly overlapping intervals, return a new list of intervals where all overlapping intervals have been merged. 6 | 7 | The input list is not necessarily ordered in any way. 8 | 9 | For example, given [(1, 3), (5, 8), (4, 10), (20, 25)], you should return [(1, 3), (4, 10), (20, 25)]. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-23/README.md: -------------------------------------------------------------------------------- 1 | # Problem 23-09-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | Given k sorted singly linked lists, write a function to merge all the lists into one sorted singly linked list. 6 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-24/README.md: -------------------------------------------------------------------------------- 1 | # Problem 24-09-2019 (TO-DO) 2 | 3 | This problem was asked by Facebook. 4 | 5 | Given an array of integers, write a function to determine whether the array could become non-decreasing by modifying at most 1 element. 6 | 7 | For example, given the array [10, 5, 7], you should return true, since we can modify the 10 into a 1 to make the array non-decreasing. 8 | 9 | Given the array [10, 5, 1], you should return false, since we can't modify any one element to get a non-decreasing array. 10 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-25/README.md: -------------------------------------------------------------------------------- 1 | # Problem 25-09-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | Given the root of a binary tree, return a deepest node. For example, in the following tree, return d. 6 | 7 | ``` 8 | a 9 | / \ 10 | b c 11 | / 12 | d 13 | ``` 14 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-26/README.md: -------------------------------------------------------------------------------- 1 | # Problem 26-09-2019 (TO-DO) 2 | 3 | This problem was asked by Yelp. 4 | 5 | Given a mapping of digits to letters (as in a phone number), and a digit string, return all possible letters the number could represent. You can assume each valid number in the mapping is a single digit. 6 | 7 | For example if {“2”: [“a”, “b”, “c”], 3: [“d”, “e”, “f”], …} then “23” should return [“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf"]. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-27/README.md: -------------------------------------------------------------------------------- 1 | # Problem 27-09-2019 (TO-DO) 2 | 3 | This problem was asked Microsoft. 4 | 5 | Using a read7() method that returns 7 characters from a file, implement readN(n) which reads n characters. 6 | 7 | For example, given a file with the content “Hello world”, three read7() returns “Hello w”, “orld” and then “”. 8 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-28/README.md: -------------------------------------------------------------------------------- 1 | # Problem 28-09-2019 (TO-DO) 2 | 3 | This problem was asked by Google. 4 | 5 | Invert a binary tree. 6 | 7 | For example, given the following tree: 8 | 9 | ``` 10 | a 11 | / \ 12 | b c 13 | / \ / 14 | d e f 15 | ``` 16 | 17 | should become: 18 | 19 | ``` 20 | a 21 | / \ 22 | c b 23 | \ / \ 24 | f e d 25 | ``` 26 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-29/README.md: -------------------------------------------------------------------------------- 1 | # Problem 29-09-2019 (TO-DO) 2 | 3 | This problem was asked by Amazon. 4 | 5 | Given a matrix of 1s and 0s, return the number of "islands" in the matrix. A 1 represents land and 0 represents water, so an island is a group of 1s that are neighboring whose perimeter is surrounded by water. 6 | 7 | For example, this matrix has 4 islands. 8 | 9 | ``` 10 | 1 0 0 0 0 11 | 0 0 1 1 0 12 | 0 1 1 0 0 13 | 0 0 0 0 0 14 | 1 1 0 0 1 15 | 1 1 0 0 1 16 | ``` 17 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/Problem 2019-09-30/README.md: -------------------------------------------------------------------------------- 1 | # Problem 30-09-2019 (TO-DO) 2 | 3 | This problem was asked by Facebook. 4 | 5 | Given three 32-bit integers x, y, and b, return x if b is 1 and y if b is 0, using only mathematical or bit operations. You can assume b can only be 1 or 0. 6 | -------------------------------------------------------------------------------- /Solutions/Daily Coding Problems/README.md: -------------------------------------------------------------------------------- 1 | # Subscribe at 2 | 3 | https://www.dailycodingproblem.com/ -------------------------------------------------------------------------------- /Solutions/DevSkill/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | http://www.devskill.com/Home/PublicProfile/danielbrito 4 | -------------------------------------------------------------------------------- /Solutions/DevSkill/Reverse.cpp: -------------------------------------------------------------------------------- 1 | // http://www.devskill.com/CodingProblems/ViewProblem/26 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main() { 10 | 11 | int t; 12 | string str; 13 | 14 | cin >> t; 15 | 16 | while(t--){ 17 | 18 | getline(cin, str); 19 | 20 | while (str.length()==0){ 21 | getline(cin, str); 22 | } 23 | 24 | reverse(str.begin(), str.end()); 25 | 26 | cout << str << endl; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Solutions/E-Olymp/1 - Simple Problem.cpp: -------------------------------------------------------------------------------- 1 | // https://www.e-olymp.com/en/problems/1 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int number; 10 | 11 | cin >> number; 12 | 13 | cout << number/10 << " " << number%10 << endl; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/E-Olymp/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://www.e-olymp.com/en/users/danielbrito 4 | -------------------------------------------------------------------------------- /Solutions/Edabit/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://edabit.com/user/4NvLxiZZz47vWG9To 4 | -------------------------------------------------------------------------------- /Solutions/Edabit/addition.js: -------------------------------------------------------------------------------- 1 | // https://edabit.com/challenge/3LpBLgNRyaHMvNb4j 2 | 3 | function addition(a, b) { 4 | return a+b; 5 | } -------------------------------------------------------------------------------- /Solutions/Edabit/bitwiseOperations.js: -------------------------------------------------------------------------------- 1 | // https://edabit.com/challenge/vvuAkYEAArrZvmp6X 2 | 3 | function bitwiseAND(n1, n2) { 4 | return n1 & n2; 5 | } 6 | 7 | function bitwiseOR(n1, n2) { 8 | return n1 | n2; 9 | } 10 | 11 | function bitwiseXOR(n1, n2) { 12 | return n1 ^ n2; 13 | } -------------------------------------------------------------------------------- /Solutions/Edabit/calcAge.js: -------------------------------------------------------------------------------- 1 | // https://edabit.com/challenge/bL7hSc6Zh4zZJzGmw 2 | 3 | function calcAge(age) { 4 | return age*365; 5 | } -------------------------------------------------------------------------------- /Solutions/Edabit/circuitPower.js: -------------------------------------------------------------------------------- 1 | // https://edabit.com/challenge/wAdE9te55cowBLcPs 2 | 3 | function circuitPower(voltage, current) { 4 | return voltage*current; 5 | } -------------------------------------------------------------------------------- /Solutions/Edabit/convert.js: -------------------------------------------------------------------------------- 1 | // https://edabit.com/challenge/8q54MKnRrm89pSLmW 2 | 3 | function convert(minutes) { 4 | return minutes*60; 5 | } -------------------------------------------------------------------------------- /Solutions/Edabit/hello.js: -------------------------------------------------------------------------------- 1 | // https://edabit.com/challenge/ARr5tA458o2tC9FTN 2 | 3 | function hello() { 4 | return "hello edabit.com"; 5 | } -------------------------------------------------------------------------------- /Solutions/Edabit/regexEmptyString.js: -------------------------------------------------------------------------------- 1 | // https://edabit.com/challenge/bAqxpvYmDuuvz4LQz 2 | 3 | const REGEXP = /^$/ -------------------------------------------------------------------------------- /Solutions/Exercism/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | 4 | -------------------------------------------------------------------------------- /Solutions/Exercism/c/acronym/src/acronym.h: -------------------------------------------------------------------------------- 1 | #ifndef ACRONYM_H 2 | #define ACRONYM_H 3 | 4 | char *abbreviate(const char *phrase); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /Solutions/Exercism/c/hello-world/src/hello_world.c: -------------------------------------------------------------------------------- 1 | #include "hello_world.h" 2 | 3 | const char *hello(void) 4 | { 5 | return "Hello, World!"; 6 | } -------------------------------------------------------------------------------- /Solutions/Exercism/c/hello-world/src/hello_world.h: -------------------------------------------------------------------------------- 1 | #ifndef HELLO_WORLD_H 2 | #define HELLO_WORLD_H 3 | 4 | const char *hello(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /Solutions/Exercism/c/hello-world/test/test_hello_world.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "vendor/unity.h" 3 | #include "../src/hello_world.h" 4 | 5 | void setUp(void) 6 | { 7 | } 8 | 9 | void tearDown(void) 10 | { 11 | } 12 | 13 | static void test_hello(void) 14 | { 15 | TEST_ASSERT_EQUAL_STRING("Hello, World!", hello()); 16 | } 17 | 18 | int main(void) 19 | { 20 | UnityBegin("test/test_hello_world.c"); 21 | 22 | RUN_TEST(test_hello); 23 | 24 | return UnityEnd(); 25 | } 26 | -------------------------------------------------------------------------------- /Solutions/Exercism/cpp/hello-world/hello_world.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "hello_world.h" 3 | 4 | using namespace std; 5 | 6 | string hello() { 7 | 8 | return "Hello, World!"; 9 | } -------------------------------------------------------------------------------- /Solutions/Exercism/cpp/hello-world/hello_world.h: -------------------------------------------------------------------------------- 1 | #if !defined(HELLO_WORLD_H) 2 | #define HELLO_WORLD_H 3 | 4 | #include 5 | 6 | namespace hello_world { 7 | 8 | std::string hello(); 9 | 10 | } 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /Solutions/Exercism/cpp/hello-world/hello_world_test.cpp: -------------------------------------------------------------------------------- 1 | #include "hello_world.h" 2 | #include "test/catch.hpp" 3 | 4 | TEST_CASE("test_hello") 5 | { 6 | REQUIRE("Hello, World!" == hello_world::hello()); 7 | } 8 | -------------------------------------------------------------------------------- /Solutions/Exercism/cpp/reverse-string/reverse_string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "reverse_string.h" 3 | 4 | using namespace std; 5 | 6 | string reverse_string(string str) { 7 | 8 | reverse(str.begin(), str.end()); 9 | 10 | return str; 11 | } -------------------------------------------------------------------------------- /Solutions/Exercism/java/hello-world/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "java" 2 | apply plugin: "eclipse" 3 | apply plugin: "idea" 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | testCompile "junit:junit:4.12" 11 | } 12 | 13 | test { 14 | testLogging { 15 | exceptionFormat = 'full' 16 | events = ["passed", "failed", "skipped"] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Solutions/Exercism/java/hello-world/src/main/java/Greeter.java: -------------------------------------------------------------------------------- 1 | class Greeter { 2 | 3 | String getGreeting() { 4 | 5 | return "Hello, World!"; 6 | } 7 | 8 | } -------------------------------------------------------------------------------- /Solutions/Exercism/java/hello-world/src/test/java/GreeterTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | public class GreeterTest { 6 | 7 | @Test 8 | public void testThatGreeterReturnsTheCorrectGreeting() { 9 | assertEquals("Hello, World!", new Greeter().getGreeting()); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Solutions/Exercism/java/reverse-string/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "java" 2 | apply plugin: "eclipse" 3 | apply plugin: "idea" 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | testCompile "junit:junit:4.12" 11 | } 12 | test { 13 | testLogging { 14 | exceptionFormat = 'full' 15 | events = ["passed", "failed", "skipped"] 16 | } 17 | } -------------------------------------------------------------------------------- /Solutions/Exercism/java/reverse-string/src/main/java/ReverseString.java: -------------------------------------------------------------------------------- 1 | class ReverseString { 2 | 3 | String reverse(String inputString) { 4 | 5 | return new StringBuffer(inputString).reverse().toString(); 6 | } 7 | } -------------------------------------------------------------------------------- /Solutions/Exercism/javascript/hello-world/hello-world.js: -------------------------------------------------------------------------------- 1 | // 2 | // This is only a SKELETON file for the 'Hello World' exercise. It's been provided as a 3 | // convenience to get you started writing code faster. 4 | // 5 | 6 | export const hello = (name) => { 7 | 8 | return `Hello, ${name || 'World'}!` 9 | }; 10 | -------------------------------------------------------------------------------- /Solutions/Exercism/javascript/hello-world/hello-world.spec.js: -------------------------------------------------------------------------------- 1 | import { hello } from './hello-world'; 2 | 3 | describe('Hello World', () => { 4 | test('Say Hi!', () => { 5 | expect(hello()).toEqual('Hello, World!'); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /Solutions/Exercism/javascript/reverse-string/reverse-string.js: -------------------------------------------------------------------------------- 1 | // 2 | // This is only a SKELETON file for the 'Reverse String' exercise. It's been provided as a 3 | // convenience to get you started writing code faster. 4 | // 5 | 6 | export const reverseString = (str) => { 7 | 8 | return str.split("").reverse().join(""); 9 | }; 10 | -------------------------------------------------------------------------------- /Solutions/Exercism/python/hello-world/hello_world.py: -------------------------------------------------------------------------------- 1 | def hello(): 2 | return "Hello, World!" -------------------------------------------------------------------------------- /Solutions/Exercism/python/hello-world/hello_world_test.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | import hello_world 4 | 5 | 6 | # Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 7 | 8 | class HelloWorldTest(unittest.TestCase): 9 | def test_hello(self): 10 | self.assertEqual(hello_world.hello(), 'Hello, World!') 11 | 12 | 13 | if __name__ == '__main__': 14 | unittest.main() 15 | -------------------------------------------------------------------------------- /Solutions/Exercism/python/reverse-string/reverse_string.py: -------------------------------------------------------------------------------- 1 | def reverse(text): 2 | return text[::-1] 3 | -------------------------------------------------------------------------------- /Solutions/Fuzhou University OnlineJudge/1000 - A plus B.cpp: -------------------------------------------------------------------------------- 1 | // http://acm.fzu.edu.cn/problem.php?pid=1000 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int a, b; 10 | 11 | while(cin >> a >> b){ 12 | 13 | cout << a+b << endl; 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Solutions/Fuzhou University OnlineJudge/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | http://acm.fzu.edu.cn/user.php?uname=danielbrito 4 | -------------------------------------------------------------------------------- /Solutions/GeeksForGeeks/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | https://auth.geeksforgeeks.org/user/danielbrito/ -------------------------------------------------------------------------------- /Solutions/GeeksForGeeks/missingInteger.cpp: -------------------------------------------------------------------------------- 1 | /* https://practice.geeksforgeeks.org/courses/must-do-interview-prep/ */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int t, n, sum, c; 10 | 11 | cin >> t; 12 | 13 | while(t--){ 14 | 15 | sum=0; 16 | 17 | cin >> n; 18 | 19 | for(int i=0; i> c; 22 | 23 | sum += c; 24 | } 25 | 26 | cout << (n*(n+1)/2)-sum << "\n"; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Solutions/GeeksForGeeks/squaresInNNChessboard.c: -------------------------------------------------------------------------------- 1 | /* https://practice.geeksforgeeks.org/problems/squares-in-nn-chessboard/0 */ 2 | 3 | #include 4 | 5 | int numberOfSquares(int N); 6 | 7 | int main(){ 8 | 9 | int T, N; 10 | 11 | scanf("%d", &T); 12 | 13 | while(T--){ 14 | 15 | scanf("%d", &N); 16 | 17 | printf("%d\n", numberOfSquares(N)); 18 | } 19 | 20 | return 0;; 21 | } 22 | 23 | int numberOfSquares(int N){ 24 | 25 | if(N==1){ 26 | 27 | return 1; 28 | } 29 | 30 | return (N*N) + numberOfSquares(N-1); 31 | } 32 | -------------------------------------------------------------------------------- /Solutions/HackerEarth/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | https://www.hackerearth.com/@daniel329 3 | -------------------------------------------------------------------------------- /Solutions/HackerEarth/basics-of-input-output.c: -------------------------------------------------------------------------------- 1 | /* https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/tutorial/ */ 2 | 3 | #include 4 | 5 | int main(){ 6 | int N; 7 | char S[15]; 8 | 9 | scanf("%d", &N); 10 | scanf("%s", S); 11 | 12 | printf("%d\n", N*2); 13 | printf("%s\n", S); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Solutions/HackerEarth/count-set-bits.cpp: -------------------------------------------------------------------------------- 1 | // https://www.hackerearth.com/practice/basic-programming/bit-manipulation/basics-of-bit-manipulation/tutorial/ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int n, t, count; 10 | 11 | cin >> t; 12 | 13 | while(t--){ 14 | 15 | cin >> n; 16 | 17 | count = 0; 18 | 19 | while(n){ 20 | 21 | n = n&(n-1); 22 | count++; 23 | } 24 | 25 | cout << count << "\n"; 26 | } 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Solutions/HackerEarth/range-of-integers-1.c: -------------------------------------------------------------------------------- 1 | /* https://www.hackerearth.com/pt-br/practice-onboarding/range-of-integers-1 */ 2 | 3 | #include 4 | 5 | int main(void) { 6 | 7 | // Define the two integer variables 8 | int L,R; 9 | int i; 10 | 11 | // Get L and R from the user 12 | scanf("%d", &L); 13 | scanf("%d", &R); 14 | 15 | // Write here the logic to print all integers between L and R 16 | for(i=L; i<=R; i++){ 17 | printf("%d ", i); 18 | } 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Solutions/HackerEarth/reversed-array.cpp: -------------------------------------------------------------------------------- 1 | // https://www.hackerearth.com/practice/data-structures/arrays/1-d/tutorial/ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int N; 10 | 11 | cin >> N; 12 | 13 | int array[N]; 14 | 15 | for(int i=0; i> array[i]; 18 | } 19 | 20 | for(int i=N-1; i>=0; i--){ 21 | 22 | cout << array[i] << "\n"; 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Solutions/HackerEarth/sum-of-four.c: -------------------------------------------------------------------------------- 1 | /* https://www.hackerearth.com/pt-br/practice-onboarding/sum-of-four-2 */ 2 | 3 | #include 4 | 5 | int main(void) { 6 | 7 | int numArray[4]; // Define an array of four integers 8 | int i; 9 | int sum = 0; 10 | 11 | // Get inputs for the array elements 12 | for (i=0; i<4; i++) { 13 | scanf("%d", &numArray[i]); 14 | 15 | sum+= numArray[i]; 16 | } 17 | 18 | printf("%d\n",sum); // Print the sum 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Solutions/HackerEarth/sum-of-n-1.c: -------------------------------------------------------------------------------- 1 | /* https://www.hackerearth.com/pt-br/practice-onboarding/sum-of-n-1 */ 2 | 3 | #include 4 | 5 | int main(void) { 6 | 7 | int N, i; 8 | int sum = 0; 9 | 10 | scanf("%d", &N); 11 | 12 | int numArray[N]; // Define an array of four integers 13 | 14 | // Get inputs for the array elements 15 | for (i=0;i 4 | 5 | int main(void) { 6 | 7 | int N, i; 8 | int sum = 0; 9 | scanf("%d", &N); 10 | 11 | int numArray[N]; // Define an array of four integers 12 | 13 | // Get inputs for the array elements 14 | for (i=0;i 4 | 5 | int main(){ 6 | 7 | int num1, num2; // Define two integer variables 8 | 9 | 10 | scanf("%d %d", &num1, &num2); // Get input for the two variables 11 | 12 | int sum = 0; 13 | // Write the logic to add these numbers here: 14 | sum = num1+num2; 15 | 16 | 17 | printf("%d\n", sum); // Print the sum 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Solutions/HackerEarth/welcome-to-online-programming-1.c: -------------------------------------------------------------------------------- 1 | /* https://www.hackerearth.com/pt-br/practice-onboarding/welcome-to-online-programming-1 */ 2 | 3 | #include 4 | 5 | int main() { 6 | // declare a variable to store the name 7 | char *name = (char *) malloc(100); 8 | 9 | // read the name from input 10 | scanf("%s", name); 11 | 12 | // print the name 13 | printf("Hello %s", name); 14 | } -------------------------------------------------------------------------------- /Solutions/HackerRank/APersonalizedEcho.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | read -p "" name 4 | 5 | echo "Welcome $name" 6 | -------------------------------------------------------------------------------- /Solutions/HackerRank/AfricanCities.sql: -------------------------------------------------------------------------------- 1 | select city.name 2 | from city 3 | join country on city.countrycode = country.code 4 | where country.continent = 'Africa' 5 | -------------------------------------------------------------------------------- /Solutions/HackerRank/AveragePopulation.sql: -------------------------------------------------------------------------------- 1 | select round(avg(population)) from city; 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/AveragePopulationOfEachContinent.sql: -------------------------------------------------------------------------------- 1 | select ctr.continent, floor(avg(cty.population)) from COUNTRY as ctr 2 | join CITY as cty on cty.countrycode = ctr.code 3 | group by ctr.continent 4 | -------------------------------------------------------------------------------- /Solutions/HackerRank/BirthdayCakeCandles.js: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/challenges/birthday-cake-candles/problem 2 | 3 | const candles = [4, 4, 1, 3]; 4 | 5 | function birthdayCakeCandles(candles) { 6 | const countMap = new Map(); 7 | 8 | candles.forEach((candle) => { 9 | if (countMap.has(candle)) { 10 | countMap.set(candle, countMap.get(candle) + 1); 11 | } else { 12 | countMap.set(candle, 1); 13 | } 14 | }); 15 | 16 | return Math.max(...countMap.values()); 17 | } 18 | 19 | console.log(birthdayCakeCandles(candles)); 20 | -------------------------------------------------------------------------------- /Solutions/HackerRank/BirthdayCakeCandles.ts: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/challenges/birthday-cake-candles/problem 2 | 3 | const candles = [4, 4, 1, 3]; 4 | 5 | function birthdayCakeCandles(candles: number[]): number { 6 | const maxValue = Math.max(...candles); 7 | 8 | return candles.filter((value) => value === maxValue).length; 9 | } 10 | 11 | console.log(birthdayCakeCandles(candles)); 12 | -------------------------------------------------------------------------------- /Solutions/HackerRank/BreakingTheRecords.ts: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/challenges/breaking-best-and-worst-records/problem 2 | 3 | function breakingRecords(scores: number[]): number[] { 4 | let max = scores[0]; 5 | let min = scores[0]; 6 | 7 | let countMost = 0; 8 | let countLeast = 0; 9 | 10 | scores.slice(1).forEach((score) => { 11 | if (score > max) { 12 | countMost++; 13 | max = score; 14 | } 15 | 16 | if (score < min) { 17 | countLeast++; 18 | min = score; 19 | } 20 | }); 21 | 22 | return [countMost, countLeast]; 23 | } 24 | -------------------------------------------------------------------------------- /Solutions/HackerRank/DivisibleSumPairs.ts: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/challenges/divisible-sum-pairs/problem 2 | 3 | function divisibleSumPairs(n: number, k: number, ar: number[]): number { 4 | let result = 0; 5 | 6 | for (let i = 0; i < n; i++) { 7 | for (let j = i + 1; j < n; j++) { 8 | if ((ar[i] + ar[j]) % k === 0) result++; 9 | } 10 | } 11 | 12 | return result; 13 | } 14 | -------------------------------------------------------------------------------- /Solutions/HackerRank/EmployeeNames.sql: -------------------------------------------------------------------------------- 1 | select name from Employee order by name; 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/EmployeeSalaries.sql: -------------------------------------------------------------------------------- 1 | select name from Employee 2 | where salary > 2000 and months < 10 3 | order by employee_id; 4 | -------------------------------------------------------------------------------- /Solutions/HackerRank/JapaneseCitiesAttributes.sql: -------------------------------------------------------------------------------- 1 | select * from city where countrycode = 'JPN'; 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/JapaneseCitiesNames.sql: -------------------------------------------------------------------------------- 1 | select name from city where countrycode = 'JPN'; 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/LetsEcho.sh: -------------------------------------------------------------------------------- 1 | echo "HELLO" 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/MarcsCakewalk.ts: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/challenges/marcs-cakewalk/problem 2 | 3 | function marcsCakewalk(calorie: number[]): number { 4 | let result = 0; 5 | 6 | let sortedCalories = calorie.sort((a, b) => b - a); 7 | 8 | for(let i=0; i x2 && v1 > v2) || (x2 > x1 && v2 > v1)) { 5 | return "NO"; 6 | } 7 | 8 | const diffX = Math.abs(x1 - x2); 9 | const diffV = Math.abs(v1 - v2); 10 | 11 | return diffX % diffV === 0 ? "YES" : "NO"; 12 | } 13 | -------------------------------------------------------------------------------- /Solutions/HackerRank/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://www.hackerrank.com/danielbrito 4 | -------------------------------------------------------------------------------- /Solutions/HackerRank/React Skills Certification Test (HackerRank)/Q1/74a81002-2956-4e21-a055-2768b9c03b8e/bin/env_setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash 4 | export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" 5 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm 6 | nvm install v12 7 | nvm use v12 8 | echo "install complete" 9 | exit 0 -------------------------------------------------------------------------------- /Solutions/HackerRank/React Skills Certification Test (HackerRank)/Q1/74a81002-2956-4e21-a055-2768b9c03b8e/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /Solutions/HackerRank/React Skills Certification Test (HackerRank)/Q1/74a81002-2956-4e21-a055-2768b9c03b8e/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | max-width: 600px; 3 | margin: 0 auto; 4 | margin-top: 50px; 5 | } 6 | 7 | #navigation { 8 | margin-bottom: 2rem; 9 | } 10 | 11 | #navigation button { 12 | margin-right: 1rem; 13 | } 14 | 15 | #slide { 16 | border: 1px solid #eee; 17 | padding: 1rem; 18 | min-height: 300px; 19 | } 20 | 21 | button { 22 | min-width: 80px; 23 | } 24 | -------------------------------------------------------------------------------- /Solutions/HackerRank/React Skills Certification Test (HackerRank)/Q1/74a81002-2956-4e21-a055-2768b9c03b8e/src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './App.css'; 3 | import 'h8k-components'; 4 | 5 | import Slides from './components/Slides'; 6 | const title = "Slideshow App"; 7 | 8 | function App({slides}) { 9 | return ( 10 |
11 | 12 |
13 | 14 |
15 |
16 | ); 17 | } 18 | 19 | export default App; 20 | -------------------------------------------------------------------------------- /Solutions/HackerRank/React Skills Certification Test (HackerRank)/Q1/74a81002-2956-4e21-a055-2768b9c03b8e/src/index.css: -------------------------------------------------------------------------------- 1 | @import '../node_modules/h8k-design/dist/index.css'; 2 | 3 | body { 4 | margin: 0; 5 | padding: 0; 6 | font-family: sans-serif; 7 | } 8 | -------------------------------------------------------------------------------- /Solutions/HackerRank/React Skills Certification Test (HackerRank)/Q1/74a81002-2956-4e21-a055-2768b9c03b8e/src/setupTests.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielBrito/competitive-programming/6779941f5ffff4fe5770826b1e4efdb6ca4a5d07/Solutions/HackerRank/React Skills Certification Test (HackerRank)/Q1/74a81002-2956-4e21-a055-2768b9c03b8e/src/setupTests.js -------------------------------------------------------------------------------- /Solutions/HackerRank/React Skills Certification Test (HackerRank)/Q2/afaff9c8-2336-4dbc-a09c-1d3eaceabb53/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | 23 | 24 | .idea 25 | .env 26 | -------------------------------------------------------------------------------- /Solutions/HackerRank/React Skills Certification Test (HackerRank)/Q2/afaff9c8-2336-4dbc-a09c-1d3eaceabb53/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "browser": true, 4 | "esnext": true 5 | } 6 | -------------------------------------------------------------------------------- /Solutions/HackerRank/React Skills Certification Test (HackerRank)/Q2/afaff9c8-2336-4dbc-a09c-1d3eaceabb53/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /Solutions/HackerRank/React Skills Certification Test (HackerRank)/Q2/afaff9c8-2336-4dbc-a09c-1d3eaceabb53/src/App.css: -------------------------------------------------------------------------------- 1 | .navigation button { 2 | min-width: 100px; 3 | } 4 | -------------------------------------------------------------------------------- /Solutions/HackerRank/React Skills Certification Test (HackerRank)/Q2/afaff9c8-2336-4dbc-a09c-1d3eaceabb53/src/index.css: -------------------------------------------------------------------------------- 1 | @import "../node_modules/h8k-design/dist/index.css"; 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/RevisingAggregations.sql: -------------------------------------------------------------------------------- 1 | select avg(population) 2 | from CITY 3 | where DISTRICT = 'California' 4 | -------------------------------------------------------------------------------- /Solutions/HackerRank/RevisingAggregationsTheSumFunction.sql: -------------------------------------------------------------------------------- 1 | select sum(population) 2 | from CITY 3 | where district = 'California' 4 | -------------------------------------------------------------------------------- /Solutions/HackerRank/RevisingTheSelectQueryI.sql: -------------------------------------------------------------------------------- 1 | select * from city where population > 100000 and countrycode = 'USA'; 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/RevisingTheSelectQueryII.sql: -------------------------------------------------------------------------------- 1 | select name from city where population > 120000 and countrycode = 'USA'; 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/SelectAll.sql: -------------------------------------------------------------------------------- 1 | select * from city; 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/SelectById.sql: -------------------------------------------------------------------------------- 1 | select * from city where id = 1661; 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/SubarrayDivision.ts: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/challenges/the-birthday-bar/problem 2 | 3 | function birthday(s: number[], d: number, m: number): number { 4 | let result = 0; 5 | 6 | for(let i=0; i= 38.7880 and LAT_N <= 137.2345 4 | -------------------------------------------------------------------------------- /Solutions/HackerRank/WeatherObservationStation14.sql: -------------------------------------------------------------------------------- 1 | select truncate(max(LAT_N), 4) 2 | from STATION 3 | where LAT_N < 137.2345; 4 | -------------------------------------------------------------------------------- /Solutions/HackerRank/WeatherObservationStation15.sql: -------------------------------------------------------------------------------- 1 | select round(LONG_W, 4) 2 | from STATION 3 | where LAT_N = ( 4 | select max(LAT_N) 5 | from STATION 6 | where LAT_N < 137.2345 7 | ); 8 | -------------------------------------------------------------------------------- /Solutions/HackerRank/WeatherObservationStation16.sql: -------------------------------------------------------------------------------- 1 | select round(min(LAT_N), 4) 2 | from STATION 3 | where LAT_N > 38.7780 4 | -------------------------------------------------------------------------------- /Solutions/HackerRank/WeatherObservationStation17.sql: -------------------------------------------------------------------------------- 1 | select round(LONG_W, 4) 2 | from STATION 3 | where LAT_N = ( 4 | select min(LAT_N) 5 | from STATION 6 | where LAT_N > 38.7780 7 | ); 8 | -------------------------------------------------------------------------------- /Solutions/HackerRank/WeatherObservationStation3.sql: -------------------------------------------------------------------------------- 1 | select distinct city from station where id % 2 = 0; 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/WeatherObservationStation4v1.sql: -------------------------------------------------------------------------------- 1 | select ABS(count(city) - count(distinct city)) from station; 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/WeatherObservationStation4v2.sql: -------------------------------------------------------------------------------- 1 | select abs(total_count - distinct_count) as unique_names 2 | from ( 3 | select count(city) as total_count, count(distinct city) as distinct_count 4 | from station 5 | ) as subquery; 6 | -------------------------------------------------------------------------------- /Solutions/HackerRank/WeatherObservationStation5.sql: -------------------------------------------------------------------------------- 1 | select city, length(city) as city_length from station order by city_length asc, city limit 1; 2 | select city, length(city) as city_length from station order by city_length desc, city limit 1; 3 | -------------------------------------------------------------------------------- /Solutions/HackerRank/WeatherObservationStation6.sql: -------------------------------------------------------------------------------- 1 | select city from station where city regexp '^[AEIOU]'; 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/WeatherObservationStation7.sql: -------------------------------------------------------------------------------- 1 | select distinct city from station where regexp_like(city,'[aeiou]$', 'i'); 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/WeatherObservationStation8.sql: -------------------------------------------------------------------------------- 1 | select city from station where regexp_like(city,'^[aeiou].*[aeiou]$', 'i'); 2 | -------------------------------------------------------------------------------- /Solutions/HackerRank/WeatherObservationStation9.sql: -------------------------------------------------------------------------------- 1 | select distinct city 2 | from station 3 | where not regexp_like(city, '^[aeiou]', 'i'); 4 | -------------------------------------------------------------------------------- /Solutions/HackerRank/compareTriplets.py: -------------------------------------------------------------------------------- 1 | # https://www.hackerrank.com/challenges/compare-the-triplets/problem 2 | 3 | def compareTriplets(a, b): 4 | points = [0,0] 5 | for i in range(len(a)): 6 | if a[i] > b[i]: 7 | points[0]+=1 8 | elif b[i] > a[i]: 9 | points[1]+=1 10 | return points; 11 | 12 | print(compareTriplets([1,2,3], [3,2,1])) -------------------------------------------------------------------------------- /Solutions/HackerRank/plusMinus.py: -------------------------------------------------------------------------------- 1 | # https://www.hackerrank.com/challenges/plus-minus/problem 2 | 3 | def plusMinus(arr): 4 | pos = len(list(filter(lambda x: (x > 0), arr))) 5 | neg = len(list(filter(lambda x: (x < 0), arr))) 6 | zer = len(list(filter(lambda x: (x == 0), arr))) 7 | 8 | print("{0:.6f}".format(pos/len(arr))) 9 | print("{0:.6f}".format(neg/len(arr))) 10 | print("{0:.6f}".format(zer/len(arr))) 11 | 12 | plusMinus([-4, 3, -9, 0, 4, 1]) -------------------------------------------------------------------------------- /Solutions/HackerRank/roadRepair.cpp: -------------------------------------------------------------------------------- 1 | // Certification Test - Problem Solving (Basic) 2 | 3 | long roadRepair(vector crew_id, vector job_id) { 4 | 5 | long answer=0; 6 | 7 | sort(crew_id.begin(), crew_id.end()); 8 | sort(job_id.begin(), job_id.end()); 9 | 10 | for(int i=0; i accumulator + value, 0) 5 | } 6 | 7 | console.log(simpleArraySum([1,2,3,4,5,6])); -------------------------------------------------------------------------------- /Solutions/HackerRank/simpleArraySum.py: -------------------------------------------------------------------------------- 1 | # https://www.hackerrank.com/challenges/simple-array-sum/problem 2 | 3 | def simpleArraySum(ar): 4 | return sum(int(i) for i in ar) 5 | 6 | print(simpleArraySum([1,2,3,4,5,6])) -------------------------------------------------------------------------------- /Solutions/HackerRank/solveMeFirst.c: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/solve-me-first/problem */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int solveMeFirst(int a, int b) { 9 | 10 | return a+b; 11 | } 12 | 13 | int main() { 14 | 15 | int num1,num2; 16 | 17 | scanf("%d %d",&num1,&num2); 18 | 19 | int sum; 20 | 21 | sum = solveMeFirst(num1,num2); 22 | 23 | printf("%d",sum); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Solutions/HackerRank/staircase.js: -------------------------------------------------------------------------------- 1 | /* https://www.hackerrank.com/challenges/staircase/problem */ 2 | 3 | function staircase(n) { 4 | let count = 1; 5 | let answer = ""; 6 | 7 | for(let i=0; i 4 | -------------------------------------------------------------------------------- /Solutions/International Olympiad in Informatics/README.md: -------------------------------------------------------------------------------- 1 | # Available at 2 | 3 | [International Olympiad in Informatics - Contests](https://ioinformatics.org/page/contests/10) -------------------------------------------------------------------------------- /Solutions/Kattis/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://open.kattis.com/users/daniel-brito 4 | -------------------------------------------------------------------------------- /Solutions/Kattis/hello.cpp: -------------------------------------------------------------------------------- 1 | // https://open.kattis.com/problems/hello 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | cout << "Hello World!" << endl; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Solutions/Kick Start/README.md: -------------------------------------------------------------------------------- 1 | # Available at 2 | 3 | 4 | -------------------------------------------------------------------------------- /Solutions/LeetCode/BestTimeToBuyAndSellStock.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun maxProfit(prices: IntArray): Int { 3 | var minPrice = Int.MAX_VALUE 4 | var maxProfit = 0 5 | 6 | for (price in prices) { 7 | if (price < minPrice) { 8 | minPrice = price 9 | } else if (price - minPrice > maxProfit) { 10 | maxProfit = price - minPrice 11 | } 12 | } 13 | 14 | return maxProfit 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/LeetCode/BuildArrayFromPermutation.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun buildArray(nums: IntArray): IntArray { 3 | val n = nums.size 4 | val result = IntArray(n) 5 | 6 | for(i in nums.indices) { 7 | result[i] = nums[nums[i]] 8 | } 9 | 10 | return result 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Solutions/LeetCode/CombineTwoTables.sql: -------------------------------------------------------------------------------- 1 | select p.firstName as firstname, p.lastName as lastname, a.city, a.state 2 | from person p 3 | left join address a on p.personId = a.personId; 4 | -------------------------------------------------------------------------------- /Solutions/LeetCode/ConcatenationOfArray.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun getConcatenation(nums: IntArray): IntArray { 3 | val n = nums.size 4 | val result = IntArray(n * 2) 5 | 6 | for(i in nums.indices) { 7 | result[i] = nums[i] 8 | result[i+n] = nums[i] 9 | } 10 | 11 | return result 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Solutions/LeetCode/ConvertTheTemperature.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun convertTemperature(celsius: Double): DoubleArray { 3 | val kelvin = celsius + 273.15 4 | val fahrenheit = celsius * 1.80 + 32.00 5 | 6 | return doubleArrayOf(kelvin, fahrenheit) 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Solutions/LeetCode/CountTheNumberOfConsistentStrings.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun countConsistentStrings(allowed: String, words: Array): Int { 3 | var result = 0 4 | var allowedCharSet = allowed.toSet() 5 | 6 | for(word in words) { 7 | val wordCharSet = word.toSet() 8 | val isSubset = wordCharSet.all { it in allowedCharSet } 9 | 10 | if(isSubset) result++ 11 | } 12 | 13 | return result 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Solutions/LeetCode/DefangingAnIPAddress.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun defangIPaddr(address: String): String { 3 | return address.replace(".", "[.]") 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Solutions/LeetCode/DivisibleAndNonDivisibleSumsDifference.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun differenceOfSums(n: Int, m: Int): Int { 3 | var divisible = 0 4 | var nonDivisible = 0 5 | 6 | for(i in 1..n) { 7 | if(i % m == 0) divisible += i 8 | else nonDivisible += i 9 | } 10 | 11 | return nonDivisible - divisible 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Solutions/LeetCode/EmployeeBonus.sql: -------------------------------------------------------------------------------- 1 | select e.name, b.bonus from Employee e 2 | left join Bonus b on b.empId = e.empId 3 | where b.bonus < 1000 or b.bonus is null 4 | -------------------------------------------------------------------------------- /Solutions/LeetCode/EmployeesWithMissingInformation.sql: -------------------------------------------------------------------------------- 1 | select coalesce(e.employee_id, s.employee_id) as employee_id 2 | from Employees e 3 | full join Salaries s on e.employee_id = s.employee_id 4 | where (e.name is null and e.employee_id is null) or (s.salary is null and s.employee_id is null) 5 | order by employee_id asc; 6 | -------------------------------------------------------------------------------- /Solutions/LeetCode/FindMinimumOperationToMakeAllDivisibleByThree.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun minimumOperations(nums: IntArray): Int { 3 | var result = 0 4 | 5 | for(i in nums.indices) { 6 | result += min(nums[i] % 3, 3 - (nums[i] % 3)) 7 | } 8 | 9 | return result 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Solutions/LeetCode/FindTheMaximumAchievableX.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun theMaximumAchievableX(num: Int, t: Int): Int { 3 | return num + 2 * t 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Solutions/LeetCode/FindTotalTimeSpentByEachEmployee.sql: -------------------------------------------------------------------------------- 1 | select event_day as day, emp_id, sum(out_time - in_time) as total_time 2 | from Employees 3 | group by event_day, emp_id; 4 | -------------------------------------------------------------------------------- /Solutions/LeetCode/FindValueAfterOperations.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun finalValueAfterOperations(operations: Array): Int { 3 | var result = 0 4 | 5 | for(op in operations) { 6 | when(op) { 7 | "--X" -> --result 8 | "X--" -> result-- 9 | "++X" -> ++result 10 | "X++" -> result++ 11 | } 12 | } 13 | 14 | return result 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/LeetCode/FindWordsContainingCharacter.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun findWordsContaining(words: Array, x: Char): List { 3 | val result = mutableListOf() 4 | 5 | for(i in words.indices) { 6 | if(words[i].contains(x)) { 7 | result.add(i) 8 | } 9 | } 10 | 11 | return result 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Solutions/LeetCode/GoalParserInterpretationV1.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun interpret(command: String): String { 3 | return command 4 | .replace("()", "o") 5 | .replace("(al)", "al") 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Solutions/LeetCode/JewelsAndStones.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun numJewelsInStones(jewels: String, stones: String): Int { 3 | val stoneCount = mutableMapOf() 4 | var result = 0 5 | 6 | for(stone in stones) { 7 | stoneCount[stone] = stoneCount.getOrDefault(stone, 0) + 1 8 | } 9 | 10 | for((stone, count) in stoneCount) { 11 | val isJewel = jewels.indexOf(stone) != -1 12 | 13 | if(isJewel) result += count 14 | } 15 | 16 | return result 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Solutions/LeetCode/KidsWithGreatestNumberOfCandies.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun kidsWithCandies(candies: IntArray, extraCandies: Int): List { 3 | val maxCandies = candies.max() 4 | val n = candies.size 5 | val result = MutableList(n) { false } 6 | 7 | candies.forEachIndexed { index, value -> 8 | if(value + extraCandies >= maxCandies) { 9 | result[index] = true 10 | } 11 | } 12 | 13 | return result 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Solutions/LeetCode/MaximumNumberOfWordsFoundInSentences.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun mostWordsFound(sentences: Array): Int { 3 | val wordCount = buildMap { 4 | sentences.forEach { sentence -> 5 | put(sentence, sentence.split(" ").size) 6 | } 7 | } 8 | 9 | return wordCount.maxBy { it.value }.value 10 | } 11 | } 12 | 13 | /* 14 | class Solution { 15 | fun mostWordsFound(sentences: Array): Int { 16 | return sentences.maxOf { it.split(" ").size } 17 | } 18 | } 19 | */ 20 | -------------------------------------------------------------------------------- /Solutions/LeetCode/MinimumCommonValue.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun getCommon(nums1: IntArray, nums2: IntArray): Int { 3 | val set1 = nums1.toSet() 4 | val set2 = nums2.toSet() 5 | val intersection = set1.intersect(set2) 6 | 7 | return intersection.minOrNull() ?: -1 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Solutions/LeetCode/MinimumNumberGame.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun numberGame(nums: IntArray): IntArray { 3 | nums.sort() 4 | 5 | val n = nums.size 6 | val result = IntArray(n) 7 | 8 | for(i in 0 until n) { 9 | result[i] = if(i % 2 == 0) nums[i+1] else nums[i-1] 10 | } 11 | 12 | return result 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Solutions/LeetCode/NumberOfGoodPairs.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun numIdenticalPairs(nums: IntArray): Int { 3 | var result = 0 4 | var end = nums.size - 1 5 | 6 | for(i in nums.indices) { 7 | for(j in end downTo i + 1) { 8 | if(nums[i] == nums[j]) { 9 | result ++ 10 | } 11 | } 12 | } 13 | 14 | return result 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/LeetCode/NumberOfUniqueSubjectsTaughtByEachTeacher.sql: -------------------------------------------------------------------------------- 1 | select teacher_id, count(distinct subject_id) as cnt 2 | from teacher 3 | group by teacher_id; 4 | -------------------------------------------------------------------------------- /Solutions/LeetCode/PalindromeNumber.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun isPalindrome(x: Int): Boolean { 3 | if(x < 0) return false 4 | 5 | return x == reverseNumber(x) 6 | } 7 | 8 | private fun reverseNumber(num: Int): Int { 9 | var result = 0 10 | var n = num 11 | 12 | while(n != 0) { 13 | val remainder = n % 10 14 | 15 | result = result * 10 + remainder 16 | 17 | n /= 10 18 | } 19 | 20 | return result 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Solutions/LeetCode/PermutationDifferenceBetweenTwoStrings.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun findPermutationDifference(s: String, t: String): Int { 3 | var result = 0 4 | 5 | for(i in 0 until s.length) { 6 | result += Math.abs(i - t.indexOf(s[i])) 7 | } 8 | 9 | return result 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Solutions/LeetCode/ProjectEmployeesI.sql: -------------------------------------------------------------------------------- 1 | select p.project_id, round(avg(e.experience_years), 2) as average_years 2 | from Employee e 3 | join Project p on p.employee_id = e.employee_id 4 | group by p.project_id 5 | -------------------------------------------------------------------------------- /Solutions/LeetCode/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://leetcode.com/danielhbrito/ 4 | -------------------------------------------------------------------------------- /Solutions/LeetCode/RecyclableAndLowFatProducts.sql: -------------------------------------------------------------------------------- 1 | select product_id 2 | from Products 3 | where low_fats = 'Y' and recyclable = 'Y'; 4 | -------------------------------------------------------------------------------- /Solutions/LeetCode/RichestCustomerWealth.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun maximumWealth(accounts: Array): Int { 3 | var maxWealth = 0 4 | 5 | for(i in accounts.indices) { 6 | var moneySum = 0 7 | 8 | for(j in accounts[0].indices) { 9 | moneySum += accounts[i][j] 10 | } 11 | 12 | maxWealth = maxOf(moneySum, maxWealth) 13 | } 14 | 15 | return maxWealth 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Solutions/LeetCode/ScoreOfString.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun scoreOfString(s: String): Int { 3 | var score = 0 4 | 5 | for(i in 0..s.length-2) { 6 | score += Math.abs(s[i] - s[i+1]) 7 | } 8 | 9 | return score 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Solutions/LeetCode/SecondHighestSalary.sql: -------------------------------------------------------------------------------- 1 | SELECT ( 2 | SELECT DISTINCT Salary 3 | FROM Employee 4 | ORDER BY Salary DESC 5 | LIMIT 1 OFFSET 1 6 | ) AS "SecondHighestSalary" 7 | -------------------------------------------------------------------------------- /Solutions/LeetCode/ShuffleTheArray.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun shuffle(nums: IntArray, n: Int): IntArray { 3 | val result = IntArray(n*2) 4 | var firstHalfIndex = 0 5 | var secondHalfIndex = n 6 | 7 | for(i in 0 until n*2 step 2) { 8 | result[i] = nums[firstHalfIndex++] 9 | result[i+1] = nums[secondHalfIndex++] 10 | } 11 | 12 | return result 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Solutions/LeetCode/TheTwoSneakyNumbersOfDigitvile.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun getSneakyNumbers(nums: IntArray): IntArray { 3 | val countNumbers = mutableMapOf() 4 | val result = mutableListOf() 5 | 6 | nums.forEach { num -> 7 | countNumbers[num] = countNumbers.getOrDefault(num, 0) + 1 8 | } 9 | 10 | for((key, value) in countNumbers) { 11 | if(value == 2) result.add(key) 12 | } 13 | 14 | return result.toIntArray() 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/LeetCode/UniqueNumberOfOccurrences.kt: -------------------------------------------------------------------------------- 1 | class Solution { 2 | fun uniqueOccurrences(arr: IntArray): Boolean { 3 | val map = mutableMapOf() 4 | 5 | arr.forEach { 6 | if(map.containsKey(it)) map.merge(it, 1) { oldValue, _ -> oldValue + 1 } 7 | else map.put(it, 1) 8 | } 9 | 10 | return map.values.size == map.values.toSet().size 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/AprovadoOuReprovado.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/130 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | float a, b, media; 10 | 11 | cin >> a; 12 | cin >> b; 13 | 14 | media = (a+b)/2; 15 | 16 | if(media>=7){ 17 | 18 | cout << "Aprovado\n"; 19 | } 20 | else 21 | if(media<7 && media>=4){ 22 | 23 | cout << "Recuperacao\n"; 24 | } 25 | else{ 26 | 27 | cout << "Reprovado\n"; 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/AreaQuadrado.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/124 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int l 10 | 11 | cin >> l; 12 | 13 | cout << l*l << "\n"; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/Bondinho.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/problem/13 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int a, m; 10 | 11 | cin >> a; 12 | cin >> m; 13 | 14 | (a+m)<=50 ? cout << "S\n" : cout << "N\n"; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/Codigo.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/139 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | cout.tie(0); 12 | 13 | int v[100000], n, count=0; 14 | 15 | cin >> n; 16 | 17 | for(int i=0; i> v[i]; 20 | 21 | if(i>=2 && v[i]==0 && v[i-1]==0 && v[i-2]==1) ++count; 22 | } 23 | 24 | cout << count << "\n"; 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Solutions/Neps Academy/Fibonacci.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/150 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int fib(int n){ 8 | 9 | if(n<2){ 10 | 11 | return 1; 12 | } 13 | 14 | return fib(n-1)+fib(n-2); 15 | } 16 | 17 | int main(){ 18 | 19 | ios_base::sync_with_stdio(false); 20 | cin.tie(NULL); 21 | cout.tie(0); 22 | 23 | int n; 24 | 25 | cin >> n; 26 | 27 | cout << fib(n) << "\n"; 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Solutions/Neps Academy/Fliper.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/128 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int p, r; 10 | 11 | cin >> p; 12 | cin >> r; 13 | 14 | if(p==0) cout << "C\n"; 15 | 16 | if(p==1 && r==1) cout << "A\n"; 17 | 18 | if(p==1 && r==0) cout << "B\n"; 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/Game10.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/problem/17 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int n, d, a; 10 | 11 | cin >> n; 12 | cin >> d; 13 | cin >> a; 14 | 15 | if(ad){ 21 | 22 | cout << (n-a)+d << "\n"; 23 | } 24 | else{ 25 | 26 | cout << 0 << "\n"; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/Gangorra.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/125 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int p1, c1, p2, c2; 10 | 11 | cin >> p1 >> c1 >> p2 >> c2; 12 | 13 | if(p1*c1 == p2*c2){ 14 | 15 | cout << "0\n"; 16 | } 17 | else 18 | if(p1*c1 > p2*c2){ 19 | 20 | cout << "-1\n"; 21 | } 22 | else{ 23 | 24 | cout << "1\n"; 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/Garcom.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/132 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int n, l, c, total=0; 10 | 11 | cin >> n; 12 | 13 | while(n--){ 14 | 15 | cin >> l >> c; 16 | 17 | if(l>c) total+=c; 18 | } 19 | 20 | cout << total << "\n"; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/Gincana.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/problem/3 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | long int gcd(long int a, long int b) { 8 | 9 | if (b==0) return a; 10 | 11 | return gcd(b, a%b); 12 | } 13 | 14 | int main(){ 15 | 16 | long int m, n; 17 | 18 | cin >> m >> n; 19 | 20 | for(long int x=n-1; x>=1; x--){ 21 | 22 | if(gcd(m, x)==1){ 23 | 24 | cout << x << "\n"; 25 | 26 | break; 27 | } 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/Lampadas.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/133 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | long n, i; 10 | int x; 11 | bool a, b; 12 | 13 | a = b = false; 14 | 15 | cin >> n; 16 | 17 | for(i=0; i> x; 20 | 21 | if(x==1){ 22 | 23 | a = !a; 24 | } 25 | else{ 26 | 27 | a = !a; 28 | b = !b; 29 | } 30 | } 31 | 32 | cout << a << "\n"; 33 | cout << b << "\n"; 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/MediaInteira.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/122 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int a, b; 10 | 11 | cin >> a; 12 | cin >> b; 13 | 14 | cout << (a+b)/2 << "\n"; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/OlaNepsAcademy.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/problem/1 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | cout << "Ola Neps Academy!\n"; 10 | 11 | return 0; 12 | } -------------------------------------------------------------------------------- /Solutions/Neps Academy/Operacoes.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/145 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | cout.tie(0); 12 | 13 | char c; 14 | double x, y; 15 | 16 | cin >> c; 17 | cin >> x >> y; 18 | 19 | if(c=='M'){ 20 | 21 | cout << fixed << setprecision(2) << x*y << "\n"; 22 | } 23 | else{ 24 | 25 | cout << fixed << setprecision(2) << x/y << "\n"; 26 | } 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Solutions/Neps Academy/ParOuImpar.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/127 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int a, b; 10 | 11 | cin >> a; 12 | cin >> b; 13 | 14 | cout << (((a+b)&1) ? "Cino\n" : "Bino\n"); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/PositivoNegativoNulo.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/129 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int x; 10 | 11 | cin >> x; 12 | 13 | if(x>0) cout << "positivo\n"; 14 | if(x<0) cout << "negativo\n"; 15 | if(x==0) cout << "nulo\n"; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/PotenciaSimples.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/137 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main(){ 10 | 11 | double x, y; 12 | 13 | cin >> x >> y; 14 | 15 | cout << fixed << setprecision(4) << pow(x, y) << "\n"; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/PremioDoMilhao.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/134 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int n, a, dia=0, soma=0; 10 | 11 | cin >> n; 12 | 13 | while(n--){ 14 | 15 | cin >> a; 16 | 17 | soma += a; 18 | 19 | if(soma<1e6){ 20 | 21 | ++dia; 22 | } 23 | } 24 | 25 | cout << dia+1 << "\n"; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://neps.academy/user/6706 4 | 5 | Check out some of my solutions with commentaries [here](https://github.com/GEMP-UFC-Crateus/neps). 6 | 7 | Checkout out some of my solutions to [Programação Básica para Competições de Programação](#) course. 8 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/Raizes.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/136 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main(){ 10 | 11 | int n, i; 12 | double x; 13 | 14 | cin >> n; 15 | 16 | for(i=0; i> x; 19 | 20 | cout << fixed << setprecision(4) << sqrt(x) << "\n"; 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/SomaFacil.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/123 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int a, b; 10 | 11 | cin >> a; 12 | cin >> b; 13 | 14 | cout << a+b << "\n"; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/Teleferico.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/problem/15 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int c, a, countTravels=0; 10 | 11 | cin >> c; 12 | cin >> a; 13 | 14 | while(a>=(c-1)){ 15 | 16 | a -= c-1; 17 | countTravels++; 18 | } 19 | 20 | a!=0 ? cout << countTravels+1 << "\n" : cout << countTravels << "\n"; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/TodosDivisores.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | long x, i; 8 | 9 | cin >> x; 10 | 11 | for(i=1; i<=x; i++){ 12 | 13 | if(x%i==0) { 14 | 15 | (x!=i) ? cout << i << " " : cout << i; 16 | } 17 | } 18 | 19 | cout << "\n"; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Solutions/Neps Academy/TorresDeHanoi.cpp: -------------------------------------------------------------------------------- 1 | // https://neps.academy/lesson/151 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int hanoi(int n){ 8 | 9 | if (n==1){ 10 | 11 | return 1; 12 | } 13 | 14 | return hanoi(n-1)*2+1; 15 | } 16 | 17 | int main(){ 18 | 19 | ios_base::sync_with_stdio(false); 20 | cin.tie(NULL); 21 | cout.tie(0); 22 | 23 | int n, t=1; 24 | 25 | while(cin >> n && n!=0){ 26 | 27 | cout << "Teste " << t++ << "\n"; 28 | 29 | cout << hanoi(n) << "\n\n"; 30 | } 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Solutions/Olimpíada Brasileira de Informática/README.md: -------------------------------------------------------------------------------- 1 | # Available at 2 | [Olimpíada Brasileira de Informática - Pratique](https://olimpiada.ic.unicamp.br/pratique/) 3 | -------------------------------------------------------------------------------- /Solutions/Olimpíada Brasileira de Informática/buscaNaInternet.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* https://www.t-obi.com/problem/show/1/1 */ 5 | 6 | int main(){ 7 | 8 | int t; 9 | scanf("%d", &t); 10 | 11 | t = 2*(2*t); 12 | 13 | printf("%d", t); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Solutions/Olimpíada Brasileira de Informática/buscaNaInternet.hs: -------------------------------------------------------------------------------- 1 | module BuscaNaInternet where 2 | 3 | access :: Int -> Int 4 | access n = f (f n) where 5 | f n = n * 2 -------------------------------------------------------------------------------- /Solutions/Olimpíada Brasileira de Informática/cometa.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* https://www.t-obi.com/problem/show/1/59 */ 5 | 6 | int main(){ 7 | 8 | int ano, prox, i=0; 9 | 10 | scanf("%d", &ano); 11 | 12 | while(1){ 13 | 14 | prox = 1986+76*(i+1); 15 | 16 | if(ano 2 | #include 3 | 4 | /* https://www.t-obi.com/problem/show/1/9 */ 5 | 6 | int main(){ 7 | 8 | int metrosPercorridos; 9 | int tamanhoDaPista; 10 | 11 | scanf("%d", &metrosPercorridos); 12 | scanf("%d", &tamanhoDaPista); 13 | 14 | printf("%d\n", metrosPercorridos%tamanhoDaPista); 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Solutions/Olimpíada Brasileira de Informática/pedagio.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* https://www.t-obi.com/problem/show/1/54 */ 5 | 6 | int main(){ 7 | 8 | int comprimentoEstrada; 9 | int distanciaPedagios; 10 | int custoKm; 11 | int valorPedagio; 12 | 13 | scanf("%d %d", &comprimentoEstrada, &distanciaPedagios); 14 | scanf("%d %d", &custoKm, &valorPedagio); 15 | 16 | printf("%d\n", (comprimentoEstrada*custoKm)+((comprimentoEstrada/distanciaPedagios)*valorPedagio)); 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Solutions/Olimpíada Brasileira de Informática/pneu.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* https://www.t-obi.com/problem/show/1/46 */ 5 | 6 | int main(){ 7 | 8 | int pressaoDesejada; 9 | int pressaoAtual; 10 | 11 | scanf("%d %d", &pressaoDesejada, &pressaoAtual); 12 | 13 | printf("%d\n", pressaoDesejada-pressaoAtual); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Solutions/Olimpíada Brasileira de Informática/receitaDeBolo.c: -------------------------------------------------------------------------------- 1 | /* https://www.t-obi.com/problem/show/2/5 */ 2 | 3 | #include 4 | 5 | int main(){ 6 | 7 | int t, o, l; 8 | 9 | scanf("%d %d %d", &t, &o, &l); 10 | 11 | t /= 2; 12 | o /= 3; 13 | l /= 5; 14 | 15 | if(t<=o && t<=l){ 16 | 17 | printf("%d", t); 18 | } 19 | else 20 | if(o<=t && o<=l){ 21 | 22 | printf("%d", o); 23 | } 24 | else{ 25 | 26 | printf("%d", l); 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Solutions/Olimpíada Brasileira de Informática/somaDeCasas.c: -------------------------------------------------------------------------------- 1 | /* https://www.t-obi.com/problem/show/5/18 */ 2 | 3 | #include 4 | #include 5 | 6 | int main(){ 7 | 8 | int* v; 9 | int qtd, soma; 10 | int i, j; 11 | 12 | scanf("%d", &qtd); 13 | 14 | v = (int*)malloc(sizeof(int)*qtd); 15 | 16 | for(i=0; i 2 | #include 3 | 4 | /* https://www.t-obi.com/problem/show/1/165 */ 5 | 6 | int main(){ 7 | 8 | int t1, t2, t3, t4; 9 | 10 | scanf("%d %d %d %d", &t1, &t2, &t3, &t4); 11 | 12 | printf("%d\n", (t1-1)+(t2-1)+(t3-1)+t4); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Solutions/Olimpíada Brasileira de Informática/xadrez.c: -------------------------------------------------------------------------------- 1 | /* https://olimpiada.ic.unicamp.br/pratique/p1/2018/f1/xadrez/ */ 2 | 3 | #include 4 | 5 | int main(){ 6 | 7 | int l, c; 8 | 9 | scanf("%d %d", &l , &c); 10 | 11 | if((l%2==1 && c%2==1) || (l%2==0 && c%2==0)){ 12 | 13 | printf("B\n"); 14 | } 15 | else{ 16 | 17 | printf("P\n"); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Solutions/PKU JudgeOnline/A+B Problem.cpp: -------------------------------------------------------------------------------- 1 | // http://poj.org/problem?id=1000 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int a, b; 10 | 11 | cin >> a >> b; 12 | 13 | cout << a+b << endl; 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /Solutions/PKU JudgeOnline/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | http://poj.org/userstatus?user_id=danielbrito 4 | -------------------------------------------------------------------------------- /Solutions/Programmr/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | 4 | -------------------------------------------------------------------------------- /Solutions/Project Euler/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | [Profile badge](https://projecteuler.net/profile/danielbrito.png) 4 | -------------------------------------------------------------------------------- /Solutions/Project Euler/problem1.cpp: -------------------------------------------------------------------------------- 1 | // https://projecteuler.net/problem=1 2 | 3 | // https://proofwiki.org/wiki/Definition:Multiple 4 | 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main(){ 10 | 11 | int sum=0; 12 | 13 | for(int i=1; i<1000; i++){ 14 | 15 | if(i%3==0 || i%5==0){ 16 | 17 | sum += i; 18 | } 19 | } 20 | 21 | cout << sum << endl; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Solutions/README.md: -------------------------------------------------------------------------------- 1 | # My solutions 2 | 3 | These are my solutions to some challenges from several programming platforms, contests, and interviews. 4 | -------------------------------------------------------------------------------- /Solutions/Sphere Online Judge/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://www.spoj.com/users/danielbrito41/ 4 | -------------------------------------------------------------------------------- /Solutions/Sphere Online Judge/lifeUniverseEverything.cpp: -------------------------------------------------------------------------------- 1 | /* https://www.spoj.com/problems/TEST/ */ 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | 10 | vector numbers; 11 | bool answer=false; 12 | 13 | int n; 14 | 15 | while(scanf("%d", &n)!=EOF){ 16 | 17 | if(n==42) answer=true; 18 | 19 | if(!answer) numbers.push_back(n); 20 | } 21 | 22 | for(int i=0; i 4 | -------------------------------------------------------------------------------- /Solutions/TechGig/firstNfirst.cpp: -------------------------------------------------------------------------------- 1 | /* https://www.techgig.com/practice/question/first-n-first/dGpqbUF6MTU3MkpFNmlMdVl5NnBod3hxblUrcDRBa2lvU3NRZ3daMzlHRT0=/1 */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | string str; 10 | 11 | cin >> str; 12 | 13 | cout << str[0]; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/Timus Online Judge/1000 - A plus B.cpp: -------------------------------------------------------------------------------- 1 | // https://acm.timus.ru/problem.aspx?space=1&num=1000 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int a, b; 10 | 11 | cin >> a >> b; 12 | 13 | cout << a+b << endl; 14 | 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /Solutions/Timus Online Judge/README.md: -------------------------------------------------------------------------------- 1 | # Available at 2 | 3 | https://acm.timus.ru/ 4 | -------------------------------------------------------------------------------- /Solutions/TopCoder/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | 4 | 5 | ## Available at 6 | 7 | 8 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1001 - Extremely Basic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1001 4 | 5 | int main() { 6 | 7 | int A, B, X; 8 | 9 | scanf("%d", &A); 10 | scanf("%d", &B); 11 | 12 | X = A + B; 13 | 14 | printf("X = %d\n", X); 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1001 - Extremely Basic.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1001 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int A, B; 10 | 11 | cin >> A; 12 | cin >> B; 13 | 14 | cout << "X = " << A+B << endl; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1002 - Area of a Circle.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1002 4 | 5 | int main() { 6 | 7 | double R, A; 8 | 9 | scanf("%lf", &R); 10 | 11 | A = 3.14159 * (R*R); 12 | 13 | printf("A=%.4lf\n", A); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1002 - Area of a Circle.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1002 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | double R; 10 | 11 | cout << setprecision(4) << fixed; 12 | 13 | cin >> R; 14 | 15 | cout << "A=" << 3.14159 * (R*R) << endl; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1003 - Simple Sum.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1003 4 | 5 | int main() { 6 | 7 | int A, B, SOMA; 8 | 9 | scanf("%d %d", &A, &B); 10 | 11 | SOMA = A+B; 12 | 13 | printf("SOMA = %d\n", SOMA); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1003 - Simple Sum.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1003 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int A, B; 10 | 11 | cin >> A >> B; 12 | 13 | cout << "SOMA = " << A+B << endl; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1004 - Simple Product.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1004 4 | 5 | int main() { 6 | 7 | int N1, N2, PROD; 8 | 9 | scanf("%d %d", &N1, &N2); 10 | 11 | PROD = N1*N2; 12 | 13 | printf("PROD = %d\n", PROD); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1004 - Simple Product.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1004 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int N1, N2; 10 | 11 | cin >> N1 >> N2; 12 | 13 | cout << "PROD = " << N1*N2 << endl; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1005 - Average 1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1005 4 | 5 | int main() { 6 | 7 | float A, B, MEDIA; 8 | 9 | scanf("%f %f", &A, &B); 10 | 11 | MEDIA = ((A*3.5)+(B*7.5))/11; 12 | 13 | printf("MEDIA = %.5f\n", MEDIA); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1005 - Average 1.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1005 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | float A, B; 10 | 11 | cout << setprecision(5) << fixed; 12 | 13 | cin >> A >> B; 14 | 15 | cout << "MEDIA = " << ((A*3.5)+(B*7.5))/11 << endl; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1006 - Average 2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1006 4 | 5 | int main() { 6 | 7 | float A, B, C, media; 8 | 9 | scanf("%f%f%f", &A, &B, &C); 10 | 11 | media = ((A*2)+(B*3)+(C*5))/10; 12 | 13 | printf("MEDIA = %.1f\n", media); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1006 - Average 2.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1006 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | float A, B, C; 10 | 11 | cout << setprecision(1) << fixed; 12 | 13 | cin >> A >> B >> C; 14 | 15 | cout << "MEDIA = " << ((A*2)+(B*3)+(C*5))/10 << endl; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1007 - Difference.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1007 4 | 5 | int main() { 6 | 7 | int A, B, C, D, dif; 8 | 9 | scanf("%d %d %d %d", &A, &B, &C, &D); 10 | 11 | dif = (A*B)-(C*D); 12 | 13 | printf("DIFERENCA = %d\n", dif); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1007 - Difference.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1007 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int A, B, C, D; 10 | 11 | cin >> A >> B >> C >> D; 12 | 13 | cout << "DIFERENCA = " << (A*B)-(C*D) << endl; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1008 - Salary.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1008 4 | 5 | int main() { 6 | 7 | int employeeNumber; 8 | int workedHours; 9 | float salaryPerHour; 10 | 11 | scanf("%d", &employeeNumber); 12 | scanf("%d", &workedHours); 13 | scanf("%f", &salaryPerHour); 14 | 15 | printf("NUMBER = %d\n", employeeNumber); 16 | printf("SALARY = U$ %.2f\n", workedHours*salaryPerHour); 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1008 - Salary.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1008 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int employeeNumber, workedHours; 10 | float salaryPerHour; 11 | 12 | cout << setprecision(2) << fixed; 13 | 14 | cin >> employeeNumber >> workedHours >> salaryPerHour; 15 | 16 | cout << "NUMBER = " << employeeNumber << endl; 17 | cout << "SALARY = U$ " << workedHours*salaryPerHour << endl; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1009 - Salary with Bonus.c: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1009 2 | 3 | #include 4 | 5 | int main() { 6 | 7 | char name[30]; 8 | double salary; 9 | double salesTotal; 10 | 11 | scanf("%s", name); 12 | scanf("%lf", &salary); 13 | scanf("%lf", &salesTotal); 14 | 15 | salary += salesTotal*0.15; 16 | 17 | printf("TOTAL = R$ %.2f\n", salary); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1009 - Salary with Bonus.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1009 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | 10 | char name[30]; 11 | double salary, salesTotal; 12 | 13 | cout << setprecision(2) << fixed; 14 | 15 | cin >> name >> salary >> salesTotal; 16 | 17 | salary += salesTotal*0.15; 18 | 19 | cout << "TOTAL = R$ " << salary << endl; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1010 - Simple Calculate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1010 4 | 5 | int main() { 6 | 7 | int code1, units1, code2, units2; 8 | float price1, price2, total; 9 | 10 | scanf("%d %d %f", &code1, &units1, &price1); 11 | scanf("%d %d %f", &code2, &units2, &price2); 12 | 13 | total = (units1*price1)+(units2*price2); 14 | 15 | printf("VALOR A PAGAR: R$ %.2f\n", total); 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1010 - Simple Calculate.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1010 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | 10 | int code1, units1, code2, units2; 11 | float price1, price2; 12 | 13 | cout << setprecision(2) << fixed; 14 | 15 | cin >> code1 >> units1 >> price1; 16 | cin >> code2 >> units2 >> price2; 17 | 18 | cout << "VALOR A PAGAR: R$ " << (units1*price1)+(units2*price2) << endl; 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1011 - Sphere.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1011 6 | 7 | int main(){ 8 | 9 | float radius; 10 | double volume; 11 | 12 | scanf("%f", &radius); 13 | 14 | volume = (4.0/3)*3.14159*(radius*radius*radius); 15 | 16 | printf("VOLUME = %.3lf\n", volume); 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1011 - Sphere.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1011 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | 10 | float radius; 11 | 12 | cout << setprecision(3) << fixed; 13 | 14 | cin >> radius; 15 | 16 | cout << "VOLUME = " << (4.0/3)*3.14159*(radius*radius*radius) << endl; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1012 - Area.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1012 6 | 7 | int main(){ 8 | 9 | double a, b, c; 10 | 11 | scanf("%lf %lf %lf", &a, &b, &c); 12 | 13 | printf("TRIANGULO: %.3lf\n", (a*c)/2); 14 | printf("CIRCULO: %.3lf\n", 3.14159*(c*c)); 15 | printf("TRAPEZIO: %.3lf\n", ((a+b)*c)/2); 16 | printf("QUADRADO: %.3lf\n", b*b); 17 | printf("RETANGULO: %.3lf\n", a*b); 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1013 - The Greatest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1013 6 | 7 | int main(){ 8 | 9 | int a,b,c,ab,abc; 10 | 11 | scanf("%d %d %d",&a,&b,&c); 12 | 13 | ab=(a+b+abs(a-b))/2; 14 | 15 | abc=(ab+c+abs(ab-c))/2; 16 | 17 | printf("%d eh o maior\n", abc); 18 | 19 | return 0; 20 | 21 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1013 - The Greatest.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1013 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | 10 | int a, b, c, ab, abc; 11 | 12 | cin >> a >> b >> c; 13 | 14 | ab=(a+b+abs(a-b))/2; 15 | 16 | abc=(ab+c+abs(ab-c))/2; 17 | 18 | cout << abc << " eh o maior" << endl; 19 | 20 | return 0; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1014 - Consumption.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1014 4 | 5 | int main(){ 6 | 7 | int distance; 8 | float fuel; 9 | 10 | scanf("%d", &distance); 11 | scanf("%f", &fuel); 12 | 13 | printf("%.3f km/l\n", distance/fuel); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1014 - Consumption.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1014 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | 10 | int distance; 11 | float fuel; 12 | 13 | cout << setprecision(3) << fixed; 14 | 15 | cin >> distance >> fuel; 16 | 17 | cout << distance/fuel << " km/l" << endl; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1015 - Distance Between Two Points.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1015 5 | 6 | int main(){ 7 | 8 | float x1, y1, x2, y2; 9 | 10 | scanf("%f %f", &x1, &y1); 11 | scanf("%f %f", &x2, &y2); 12 | 13 | printf("%.4f\n",sqrt(pow((x2-x1), 2)+pow((y2-y1), 2))); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1015 - Distance Between Two Points.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1015 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int main(){ 11 | 12 | float x1, y1, x2, y2; 13 | 14 | cout << setprecision(4) << fixed; 15 | 16 | cin >> x1 >> y1; 17 | cin >> x2 >> y2; 18 | 19 | cout << sqrt(pow((x2-x1), 2)+pow((y2-y1), 2)) << endl; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1016 - Distance.c: -------------------------------------------------------------------------------- 1 | /* https://www.urionlinejudge.com.br/judge/en/problems/view/1016 */ 2 | 3 | #include 4 | 5 | int main() { 6 | 7 | int distance; 8 | 9 | scanf("%d", &distance); 10 | 11 | printf("%d minutos\n", distance*2); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1016 - Distance.cpp: -------------------------------------------------------------------------------- 1 | /* https://www.urionlinejudge.com.br/judge/en/problems/view/1016 */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int distance; 10 | 11 | cin >> distance; 12 | 13 | cout << distance*2 << " minutos" << endl; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1017 - Fuel Spent.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* https://www.urionlinejudge.com.br/judge/en/problems/view/1017 */ 4 | 5 | int main(){ 6 | 7 | int timeSpent; 8 | int speed; 9 | 10 | scanf("%d", &timeSpent); 11 | scanf("%d", &speed); 12 | 13 | float amount; 14 | 15 | amount = (float)(timeSpent*speed)/12; 16 | 17 | printf("%.3f\n", amount); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1017 - Fuel Spent.cpp: -------------------------------------------------------------------------------- 1 | /* https://www.urionlinejudge.com.br/judge/en/problems/view/1017 */ 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | 10 | int timeSpent, speed; 11 | 12 | cout << setprecision(3) << fixed; 13 | 14 | cin >> timeSpent >> speed; 15 | 16 | float amount; 17 | 18 | cout << (float)(timeSpent*speed)/12 << endl; 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1019 - Time Conversion.c: -------------------------------------------------------------------------------- 1 | /* https://www.urionlinejudge.com.br/judge/en/problems/view/1019 */ 2 | 3 | #include 4 | 5 | int main(){ 6 | 7 | int N, hour=0, minutes=0, seconds=0; 8 | 9 | scanf("%d", &N); 10 | 11 | minutes = N/60; 12 | seconds = N%60; 13 | 14 | if(minutes>60){ 15 | 16 | hour = minutes/60; 17 | minutes = minutes%60; 18 | } 19 | 20 | printf("%d:%d:%d\n", hour, minutes, seconds); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1019 - Time Conversion.cpp: -------------------------------------------------------------------------------- 1 | /* https://www.urionlinejudge.com.br/judge/en/problems/view/1019 */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int N, hour=0, minutes=0, seconds=0; 10 | 11 | cin >> N; 12 | 13 | minutes = N/60; 14 | seconds = N%60; 15 | 16 | if(minutes>60){ 17 | 18 | hour = minutes/60; 19 | minutes = minutes%60; 20 | } 21 | 22 | cout << hour << ":" << minutes << ":" << seconds << endl; 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1020 - Age in days.c: -------------------------------------------------------------------------------- 1 | /* https://www.urionlinejudge.com.br/judge/en/problems/view/1020 */ 2 | 3 | #include 4 | 5 | int main(){ 6 | 7 | int N, days=0, months=0, years=0; 8 | 9 | scanf("%d", &N); 10 | 11 | years = N/365; 12 | N = N%365; 13 | months = N/30; 14 | days = N%30; 15 | 16 | printf("%d ano(s)\n%d mes(es)\n%d dia(s)\n", years, months, days); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1020 - Age in days.cpp: -------------------------------------------------------------------------------- 1 | /* https://www.urionlinejudge.com.br/judge/en/problems/view/1020 */ 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int N, days=0, months=0, years=0; 10 | 11 | cin >> N; 12 | 13 | years = N/365; 14 | N = N%365; 15 | months = N/30; 16 | days = N%30; 17 | 18 | cout << years << " ano(s)\n" << months << " mes(es)\n" << days << " dia(s)\n"; 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1035 - Selection Test 1.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1035 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int A, B, C, D; 10 | 11 | cin >> A >> B >> C >> D; 12 | 13 | if(B>C && D>A && (C+D)>(A+B) && C>=0 && D>=0 && A%2==0){ 14 | 15 | cout << "Valores aceitos\n"; 16 | } 17 | else{ 18 | 19 | cout << "Valores nao aceitos\n"; 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1037 - Interval.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1037 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | double n; 10 | 11 | cin >> n; 12 | 13 | if(n>=0 && n<=25) cout << "Intervalo [0,25]\n"; 14 | else 15 | if(n>25 && n<=50) cout << "Intervalo (25,50]\n"; 16 | else 17 | if(n>50 && n<=75) cout << "Intervalo (50,75]\n"; 18 | else 19 | if(n>75 && n<=100) cout << "Intervalo (75,100]\n"; 20 | else 21 | cout << "Fora de intervalo\n"; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1059 - Even Number.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1059 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | for(int i=2; i<=100; i+=2){ 10 | 11 | cout << i << "\n"; 12 | } 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1065 - Even Between Five Numbers.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1065 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | cout.tie(0); 12 | 13 | int n = 5, value, count=0; 14 | 15 | while(n--){ 16 | 17 | cin >> value; 18 | 19 | if(value%2==0) ++count; 20 | } 21 | 22 | cout << count << " valores pares"; 23 | 24 | cout << "\n"; 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1070 - Six Odd Numbers.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1070 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int x, count=0; 10 | 11 | cin >> x; 12 | 13 | for (int i=x; count<6; i++){ 14 | 15 | if(i%2==1){ 16 | 17 | cout << i << endl; 18 | count++; 19 | } 20 | } 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1097 - Sequence IJ 3.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1097 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int count = 0; 10 | 11 | for(int i=1; i<=9; i+=2){ 12 | 13 | for(int j=i+6; count<3; j--){ 14 | 15 | cout << "I=" << i << " J=" << j << endl; 16 | count++; 17 | } 18 | 19 | count = 0; 20 | } 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1153 - Simple Factorial.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1153 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | long result=1; 10 | int N; 11 | 12 | cin >> N; 13 | 14 | while(N>0){ 15 | 16 | result *= N--; 17 | } 18 | 19 | cout << result << "\n"; 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1157 - Divisors I.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1157 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int n; 10 | 11 | cin >> n; 12 | 13 | for(int i=1; i<=n; i++){ 14 | 15 | if(n%i==0){ 16 | 17 | cout << i << "\n"; 18 | } 19 | } 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1161 - Factorial Sum.c: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1161 2 | 3 | #include 4 | 5 | long long int factorial(int n){ 6 | 7 | return n==0 ? 1 : n * factorial(n-1); 8 | } 9 | 10 | int main(){ 11 | 12 | int m[99999], n[99999]; 13 | int i=0, j=0; 14 | 15 | while(scanf("%d %d", &m[i++], &n[j++]) != EOF){} 16 | 17 | for (i=0; i 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int t, r1, r2; 10 | 11 | cin >> t; 12 | 13 | while(t--){ 14 | 15 | cin >> r1 >> r2; 16 | 17 | cout << r1 + r2 << "\n"; 18 | } 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1866 - Bill.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1866 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int C, N; 10 | 11 | cin >> C; 12 | 13 | while(C--){ 14 | 15 | cin >> N; 16 | 17 | N%2==0 ? cout << 0 << endl : cout << 1 << endl; 18 | 19 | } 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1924 - Vitoria and her indecision.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1924 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int n; 10 | string course; 11 | 12 | cin >> n; 13 | 14 | while(n--){ 15 | 16 | cin >> course; 17 | } 18 | 19 | cout << "Ciencia da Computacao" << "\n"; 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1930 - Electrical Outlet.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1930 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | cout.tie(0); 12 | 13 | int t1, t2, t3, t4; 14 | 15 | cin >> t1 >> t2 >> t3 >> t4; 16 | 17 | cout << t1+t2+t3+t4-3 << "\n"; 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/1933 - Tri-du.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/1933 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int a, b; 10 | 11 | cin >> a >> b; 12 | 13 | if(a==b){ 14 | 15 | cout << a << "\n"; 16 | } 17 | 18 | if(a>b){ 19 | 20 | cout << a << "\n"; 21 | } 22 | 23 | if(b>a){ 24 | 25 | cout << b << "\n"; 26 | } 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/2058 - Triangles and Regular Polygons.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/2058 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | unsigned long long int n, sumAngles=0; 10 | 11 | cin >> n; 12 | 13 | sumAngles = (n-2)*180; 14 | 15 | cout << sumAngles/180 << "\n"; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/2374 - Pneu.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/2374 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int m, n; 10 | 11 | cin >> n; 12 | cin >> m; 13 | 14 | cout << n-m << "\n"; 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/2388 - Tacógrafo.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/2388 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int n, t, v; 10 | long int totalDistance=0; 11 | 12 | cin >> n; 13 | 14 | while(n--){ 15 | 16 | cin >> t >> v; 17 | 18 | totalDistance += v*t; 19 | } 20 | 21 | cout << totalDistance << "\n"; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/2413 - Busca na Internet.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/2413 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int t; 10 | 11 | cin >> t; 12 | 13 | cout << 2*2*t << "\n"; 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/2544 - Kage Bunshin no Jutsu.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/2544 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int n; 10 | 11 | while(cin >> n){ 12 | 13 | cout << log2(n) << "\n"; 14 | } 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/2702 - Hard Choice.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/2702 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int Ca, Ba, Pa, Cr, Br, Pr; 10 | int result = 0; 11 | 12 | cin >> Ca >> Ba >> Pa; 13 | cin >> Cr >> Br >> Pr; 14 | 15 | if(Ca < Cr) result += Cr-Ca; 16 | if(Ba < Br) result += Br-Ba; 17 | if(Pa < Pr) result += Pr-Pa; 18 | 19 | cout << result << "\n"; 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/2753 - Output7.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/2753 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | for(int i=97; i<=122; i++){ 10 | 11 | char c = i; 12 | 13 | cout << i << " e " << c << "\n"; 14 | 15 | // cout << i << " e " << static_cast(i) << "\n"; 16 | } 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/2861 - The Output.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/2861 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int c; 10 | string question; 11 | 12 | cin >> c; 13 | 14 | while(c--){ 15 | 16 | cin >> question; 17 | 18 | cout << "gzuz" << "\n"; 19 | } 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/2936 - How Much Cassava.cpp: -------------------------------------------------------------------------------- 1 | // https://www.urionlinejudge.com.br/judge/en/problems/view/2936 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int n, total=0; 10 | 11 | cin >> n; 12 | total = n*300; 13 | 14 | cin >> n; 15 | total += n*1500; 16 | 17 | cin >> n; 18 | total += n*600; 19 | 20 | cin >> n; 21 | total += n*1000; 22 | 23 | cin >> n; 24 | total += n*150; 25 | 26 | cout << total+225 << "\n"; 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Solutions/URI Online Judge/3058 - Supermercado.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | 8 | int n; 9 | double p, g, x, min=numeric_limits::max(); 10 | 11 | cin >> n; 12 | 13 | while(n--){ 14 | 15 | cin >> p >> g; 16 | 17 | x = (1000/g)*p; 18 | 19 | if(x 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int h, m; 10 | 11 | // Reading input data until EOF: 12 | while (cin >> h >> m){ 13 | 14 | // Notice that 1 hr = 30° and 1 min = 6°: 15 | printf("%.2d:%.2d\n", h/30, m/6); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Solutions/URI Online Judge/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://www.urionlinejudge.com.br/judge/en/profile/69427 4 | 5 | Check out some of my solutions with commentaries [here](https://github.com/GEMP-UFC-Crateus/uri). 6 | -------------------------------------------------------------------------------- /Solutions/UVa Online Judge/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | [User statistics](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_authorstats&userid=1066913) 4 | -------------------------------------------------------------------------------- /Solutions/Zhejiang University Online Judge/1000 - A plus B.cpp: -------------------------------------------------------------------------------- 1 | // https://zoj.pintia.cn/problem-sets/91827364500/problems/91827364500 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int a, b; 10 | 11 | while(cin >> a >> b){ 12 | 13 | cout << a+b << endl; 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Solutions/Zhejiang University Online Judge/README.md: -------------------------------------------------------------------------------- 1 | # Profile 2 | 3 | https://zoj.pintia.cn/profile/statistics 4 | -------------------------------------------------------------------------------- /Studies/Arguments/README.md: -------------------------------------------------------------------------------- 1 | # Steps 2 | 3 | Useful for a large number of test cases. 4 | 5 | Compile: `g++ -o main numbers_sum.cpp` 6 | 7 | Run: `./main numbers.txt` 8 | -------------------------------------------------------------------------------- /Studies/Arguments/numbers_sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(int argc, char *argv[]){ 6 | 7 | ifstream infile("numbers.txt"); 8 | 9 | if (!infile.is_open()) return 1; 10 | 11 | string line; 12 | int number, sum=0; 13 | 14 | while(getline(infile, line)) { 15 | 16 | stringstream iss(line); 17 | 18 | if(!(iss >> number)) break; 19 | 20 | // Logic: 21 | sum += a; 22 | } 23 | 24 | cout << sum << "\n"; 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Studies/C++ Tutorial (W3Schools)/ClassesConstructors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class MyClass{ // The class 6 | 7 | public: // Access specifier 8 | MyClass(){ // Constructor 9 | 10 | cout << "Hello World!\n"; 11 | } 12 | }; 13 | 14 | int main(){ 15 | 16 | MyClass myObj; // Create an object of MyClass (this will call the constructor) 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Studies/C++ Tutorial (W3Schools)/ClassesMethods1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class MyClass{ // The class 7 | 8 | public: // Access specifier 9 | void myMethod(){ // Method/function defined inside the class 10 | 11 | cout << "Hello World!\n"; 12 | } 13 | }; 14 | 15 | int main(){ 16 | 17 | MyClass myObj; // Create an object of MyClass 18 | 19 | myObj.myMethod(); // Call the method 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Studies/C++ Tutorial (W3Schools)/ClassesMethodsParameters.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class Car{ 6 | 7 | public: 8 | int speed(int maxSpeed); 9 | }; 10 | 11 | int Car::speed(int maxSpeed){ 12 | 13 | return maxSpeed; 14 | } 15 | 16 | int main(){ 17 | 18 | Car myObj; // Create an object of Car 19 | 20 | cout << myObj.speed(200) << endl; // Call the method with an argument 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Studies/C++ Tutorial (W3Schools)/ClassesOutsideMethod1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class MyClass{ // The class 7 | 8 | public: // Access specifier 9 | void myMethod(); // Method/function declaration 10 | }; 11 | 12 | // Method/function definition outside the class 13 | void MyClass::myMethod(){ 14 | 15 | cout << "Hello World!\n"; 16 | } 17 | 18 | int main(){ 19 | 20 | MyClass myObj; // Create an object of MyClass 21 | 22 | myObj.myMethod(); // Call the method 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Studies/C++ Tutorial (W3Schools)/ExceptionExample1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | try{ 8 | 9 | int age = 15; 10 | 11 | if (age > 18){ 12 | 13 | cout << "Access granted - you are old enough.\n"; 14 | } 15 | else{ 16 | 17 | throw(age); 18 | } 19 | } 20 | catch (int myNum){ 21 | 22 | cout << "Access denied - You must be at least 18 years old.\n"; 23 | cout << "Age is: " << myNum << "\n"; 24 | } 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Studies/C++ Tutorial (W3Schools)/ExceptionExample2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | try{ 8 | 9 | int age = 20; 10 | 11 | if (age > 18){ 12 | 13 | cout << "Access granted - you are old enough.\n"; 14 | } 15 | else{ 16 | 17 | throw 505; 18 | } 19 | } 20 | catch (...) { // Handles any type of exception 21 | 22 | cout << "Access denied - You must be at least 18 years old.\n"; 23 | } 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Studies/C++ Tutorial (W3Schools)/FilesCreateWrite.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | 8 | // Create and open a text file 9 | ofstream MyFile("filename.txt"); 10 | 11 | // Write to the file 12 | MyFile << "Files can be tricky, but it is fun enough!"; 13 | 14 | // Close the file 15 | MyFile.close(); 16 | } -------------------------------------------------------------------------------- /Studies/C++ Tutorial (W3Schools)/README.md: -------------------------------------------------------------------------------- 1 | # Available at 2 | 3 | https://www.w3schools.com/cpp/default.asp 4 | -------------------------------------------------------------------------------- /Studies/C++ Tutorial (W3Schools)/filename.txt: -------------------------------------------------------------------------------- 1 | Files can be tricky, but it is fun enough! -------------------------------------------------------------------------------- /Studies/Complexidade - NEPS/o_1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | O(1): 3 | 4 | Um algoritmo que sempre vai demorar a mesma quantidade de tempo, independente da entrada, ou seja, de tempo constante. 5 | */ 6 | 7 | #include 8 | 9 | using namespace std; 10 | 11 | int main(){ 12 | 13 | int a, b, c; 14 | 15 | cin >> a >> b; 16 | 17 | c = a + b; 18 | 19 | cout << c; 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Studies/Complexidade - NEPS/o_n.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | O(​n) 3 | 4 | Conhecido como linear. Geralmente um loop que vai de 0 a algum múltiplo fixo de n. 5 | */ 6 | 7 | #include 8 | 9 | using namespace std; 10 | 11 | int main(){ 12 | 13 | int n; 14 | 15 | cin >> n; 16 | 17 | int* x = (int*)malloc(sizeof(int)*n); 18 | 19 | for(int i = 0; i < n; ++i){ 20 | 21 | cin >> x[i]; 22 | } 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Studies/Complexidade - NEPS/o_sqrtn.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | O(√​n) 3 | 4 | Um algoritmo que cresce como a raiz do próprio n, assim se multiplicamos n por quatro, esse programa demora 5 | 2 vezes a mais que antes. 6 | */ 7 | 8 | #include 9 | 10 | using namespace std; 11 | 12 | int main(){ 13 | 14 | // calcula a parte inteira da raiz de n 15 | int n, sq; 16 | 17 | cin >> n; 18 | 19 | for(sq = 1; sq*sq <= n; ++sq); 20 | --sq; 21 | 22 | cout << sq << "\n"; 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Studies/DefineAndPair.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define MAX 3 6 | #define ID users[i].first 7 | #define NAME users[i].second 8 | 9 | int main(){ 10 | 11 | int id; 12 | string name; 13 | 14 | vector> users; 15 | 16 | for(int i=0; i> id >> name; 19 | 20 | users.push_back({id, name}); 21 | } 22 | 23 | for(int i=0; i": ">", 8 | '"': """, 9 | "'": "'" 10 | }; 11 | 12 | return str 13 | .split("") 14 | .map(entity => htmlEntities[entity] || entity) 15 | .join(""); 16 | } 17 | 18 | convertHTML("Dolce & Gabbana"); -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/destroyer.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/seek-and-destroy 2 | 3 | function destroyer(arr, ...values) { 4 | return arr.filter(elem => !values.includes(elem));; 5 | } 6 | 7 | destroyer([1, 2, 3, 1, 2, 3], 2, 3); -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/diffArray.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays 2 | 3 | function diffArray(arr1, arr2) { 4 | return arr1 5 | .concat(arr2) 6 | .filter(item => !arr1.includes(item) || !arr2.includes(item)); 7 | } 8 | 9 | diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]); -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/dropElements.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/drop-it 2 | 3 | function dropElements(arr, func) { 4 | while (arr.length > 0 && !func(arr[0])) { 5 | arr.shift(); 6 | } 7 | return arr; 8 | } 9 | 10 | dropElements([1, 2, 3], function(n) {return n < 3; }); -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/fearNoLetter.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/missing-letters 2 | 3 | function fearNotLetter(str) { 4 | for (let i = 1; i < str.length; ++i) { 5 | if (str.charCodeAt(i) - str.charCodeAt(i - 1) > 1) { 6 | return String.fromCharCode(str.charCodeAt(i - 1) + 1); 7 | } 8 | } 9 | } 10 | 11 | fearNotLetter("abce"); 12 | -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/myReplace.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/search-and-replace 2 | 3 | function myReplace(str, before, after) { 4 | var index = str.indexOf(before); 5 | 6 | if (str[index] === str[index].toUpperCase()) { 7 | after = after.charAt(0).toUpperCase() + after.slice(1); 8 | } 9 | else { 10 | after = after.charAt(0).toLowerCase() + after.slice(1); 11 | } 12 | 13 | str = str.replace(before, after); 14 | 15 | return str; 16 | } -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/pairElement.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/dna-pairing 2 | 3 | function pairElement(str) { 4 | var pairs = { 5 | A: "T", 6 | T: "A", 7 | C: "G", 8 | G: "C" 9 | }; 10 | 11 | var arr = str.split(""); 12 | 13 | return arr.map(el => [el, pairs[el]]); 14 | } 15 | 16 | pairElement("GCG"); -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/spinalCase.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/spinal-tap-case 2 | 3 | function spinalCase(str) { 4 | return str 5 | .split(/\s|_|(?=[A-Z])/) 6 | .join("-") 7 | .toLowerCase(); 8 | } 9 | 10 | spinalCase('This Is Spinal Tap'); -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/steamrollArray.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller 2 | 3 | function steamrollArray(arr) { 4 | const flattenedArray = []; 5 | 6 | for (let i = 0; i < arr.length; i++) { 7 | if (Array.isArray(arr[i])) { 8 | flattenedArray.push(...steamrollArray(arr[i])); 9 | } 10 | else { 11 | flattenedArray.push(arr[i]); 12 | } 13 | } 14 | 15 | return flattenedArray; 16 | }; 17 | 18 | steamrollArray([1, [2], [3, [[4]]]]); -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/sumAll.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-numbers-in-a-range 2 | 3 | function sumAll(arr) { 4 | return (arr[0]+arr[1])*((Math.abs(arr[0]-arr[1])+1)/2) 5 | } 6 | 7 | console.log(sumAll([1, 4])); -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/sumFibs.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-odd-fibonacci-numbers 2 | 3 | function sumFibs(num) { 4 | if (num <= 0) return 0; 5 | 6 | const arrFib = [1, 1]; 7 | let nextFib = 0; 8 | 9 | while ((nextFib = arrFib[0] + arrFib[1]) <= num) { 10 | arrFib.unshift(nextFib); 11 | } 12 | 13 | return arrFib.filter(x => x % 2 != 0).reduce((a, b) => a + b); 14 | } 15 | 16 | sumFibs(4); -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/sumPrimes.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-primes 2 | 3 | function sumPrimes(num) { 4 | function isPrime(num) { 5 | for (let i = 2; i <= Math.sqrt(num); i++) { 6 | if (num % i == 0) 7 | return false; 8 | } 9 | 10 | return true; 11 | } 12 | 13 | let sum = 0; 14 | 15 | for (let i = 2; i <= num; i++) { 16 | if (isPrime(i)) 17 | sum += i; 18 | } 19 | 20 | return sum; 21 | } 22 | 23 | sumPrimes(10); -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/translatePigLatin.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin 2 | 3 | function translatePigLatin(str) { 4 | if (str.match(/^[aeiou]/)) return str + "way"; 5 | 6 | const consonantCluster = str.match(/[^aeiou]+/)[0]; 7 | return str.substring(consonantCluster.length) + consonantCluster + "ay"; 8 | } -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/truthCheck.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/everything-be-true 2 | 3 | function truthCheck(collection, pre) { 4 | return collection.every(function(element) { 5 | return element.hasOwnProperty(pre) && Boolean(element[pre]); 6 | }); 7 | } 8 | 9 | truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex"); -------------------------------------------------------------------------------- /Studies/JavaScript Algorithms (freeCodeCamp)/uniteUnique.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sorted-union 2 | 3 | function uniteUnique(...arrays) { 4 | let arr = [] 5 | arr = arr.concat(...arrays); 6 | return [...new Set(arr)]; 7 | } 8 | 9 | uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]); -------------------------------------------------------------------------------- /Studies/JavaScript Projects (freeCodeCamp)/palindrome.js: -------------------------------------------------------------------------------- 1 | // https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker 2 | 3 | function palindrome(str) { 4 | let newStr = str.toLowerCase().replace(/[^a-zA-Z0-9\\s]/g, ""); 5 | return newStr === newStr.split("").reverse().join(""); 6 | } 7 | 8 | palindrome("My age is 0, 0 si ega ym."); -------------------------------------------------------------------------------- /Studies/JavaScript Projects (freeCodeCamp)/telephoneCheck.js: -------------------------------------------------------------------------------- 1 | function telephoneCheck(str) { 2 | var regex = /^(1\s?)?(\(\d{3}\)|\d{3})[\s\-]?\d{3}[\s\-]?\d{4}$/; 3 | return regex.test(str); 4 | } 5 | 6 | console.log(telephoneCheck("555-555-5555")); 7 | -------------------------------------------------------------------------------- /Studies/MatrixJS.js: -------------------------------------------------------------------------------- 1 | const arr = Array(3) 2 | .fill(0) 3 | .map(() => Array(3).fill(0)); 4 | 5 | for (let i = 0; i < arr.length; i++) { 6 | for (let j = 0; j < arr[0].length; j++) { 7 | process.stdout.write(`${arr[i][j]} `); 8 | } 9 | 10 | console.log(""); 11 | } 12 | -------------------------------------------------------------------------------- /Studies/README.md: -------------------------------------------------------------------------------- 1 | # Studies 2 | 3 | Algorithmic analysis and study resources. 4 | -------------------------------------------------------------------------------- /Studies/bitOperation1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int x = 5; // 5 (101) 8 | 9 | x <<= 3; // Shifting bits to the left by 3 places 10 | 11 | cout << x << endl; // 40 (101000) 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /Studies/bitOperation2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int x = 64; // 64 = 1000000 8 | 9 | x >>= 3; // Shifting bits to the right by 3 places 10 | 11 | cout << x << endl; // 8 (0001000) 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /Studies/defaultParameter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void myFunction(string country = "Norway"){ 7 | 8 | cout << country << "\n"; 9 | } 10 | 11 | int main(){ 12 | 13 | myFunction("Sweden"); 14 | myFunction("India"); 15 | myFunction(); 16 | myFunction("USA"); 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Studies/myDict.py: -------------------------------------------------------------------------------- 1 | # Using a dictionary to count how many times a number appears in a list: 2 | 3 | def myDict(L): 4 | 5 | nDict = {} 6 | 7 | for i in L: 8 | if i in nDict: 9 | nDict[i] += 1 10 | else: 11 | nDict[i] = 1 12 | 13 | return nDict 14 | 15 | print(myDict([1, 2, 3, 2, 3])) 16 | -------------------------------------------------------------------------------- /Studies/overloading.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int plusFunc(int x, int y){ 6 | 7 | return x + y; 8 | } 9 | 10 | double plusFunc(double x, double y){ 11 | 12 | return x + y; 13 | } 14 | 15 | int main(){ 16 | 17 | int myNum1 = plusFunc(8, 5); 18 | double myNum2 = plusFunc(4.3, 6.26); 19 | 20 | cout << "Int: " << myNum1 << "\n"; 21 | cout << "Double: " << myNum2 << "\n"; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Studies/readLine.js: -------------------------------------------------------------------------------- 1 | const readline = require('readline'); 2 | 3 | const rl = readline.createInterface({ 4 | input: process.stdin, 5 | output: process.stdout 6 | }); 7 | 8 | rl.question('What\'s your name? ', (answer) => { 9 | 10 | console.log(`Hello, ${answer}`); 11 | 12 | rl.close(); 13 | }); -------------------------------------------------------------------------------- /Studies/setPrecisionInline.cpp: -------------------------------------------------------------------------------- 1 | // http://www.cplusplus.com/reference/iomanip/setprecision/ 2 | 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | 10 | double pi = 3.14159; 11 | 12 | cout << fixed << setprecision(2) << pi << endl; 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Studies/swap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void swapNums(int &x, int &y){ 6 | 7 | int z = x; 8 | x = y; 9 | y = z; 10 | } 11 | 12 | int main(){ 13 | 14 | int firstNum = 10; 15 | int secondNum = 20; 16 | 17 | cout << "Before swap: " << "\n"; 18 | cout << firstNum << " " << secondNum << "\n"; 19 | 20 | swapNums(firstNum, secondNum); 21 | 22 | cout << "After swap: " << "\n"; 23 | cout << firstNum << " " << secondNum << "\n"; 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Studies/use-recursion-to-create-a-range-of-numbers.js: -------------------------------------------------------------------------------- 1 | function rangeOfNumbers(startNum, endNum) { 2 | 3 | if(startNum===endNum){ 4 | 5 | return [endNum]; 6 | } 7 | else{ 8 | 9 | const arr = rangeOfNumbers(startNum+1, endNum); 10 | arr.unshift(startNum); 11 | 12 | return arr; 13 | } 14 | }; 15 | 16 | console.log(rangeOfNumbers(1, 5)) --------------------------------------------------------------------------------