Basic Exercises for Competitive Programming: Python
By Jan Pol
()
About this ebook
Do you want practice for competitive programming?
This book contain more of twenty exercises with its solution written in programming language Python. Also include desktop testing for more comprension.
Related to Basic Exercises for Competitive Programming
Related ebooks
Programming Problems: Advanced Algorithms Rating: 4 out of 5 stars4/5Problem Solving in C and Python: Programming Exercises and Solutions, Part 1 Rating: 5 out of 5 stars5/5Python: Programming for Intermediates: Learn the Fundamentals of Python in 7 Days Rating: 4 out of 5 stars4/5Conceptual Programming with Python Rating: 4 out of 5 stars4/5Python from the Very Beginning Rating: 0 out of 5 stars0 ratingsScientific Computing with Python 3 Rating: 0 out of 5 stars0 ratingsEssential Algorithms: A Practical Approach to Computer Algorithms Rating: 5 out of 5 stars5/5Tiny Python Projects: Learn coding and testing with puzzles and games Rating: 4 out of 5 stars4/5Python Games from Zero to Proficiency (Beginner): Python Games From Zero to Proficiency, #1 Rating: 0 out of 5 stars0 ratingsLearn Python in One Hour: Programming by Example Rating: 3 out of 5 stars3/5Algorithm Challenges: The Dojo Collection Rating: 0 out of 5 stars0 ratingsLearn Python by Coding Video Games (Beginner): Learn Python by Coding Video Games Rating: 2 out of 5 stars2/5Python Programming: Your Beginner Guide To Learn Python in 7 Days Rating: 4 out of 5 stars4/5Data Structures with Python: Get familiar with the common Data Structures and Algorithms in Python (English Edition) Rating: 0 out of 5 stars0 ratingsNumPy: Beginner's Guide - Third Edition Rating: 4 out of 5 stars4/5C Programming Language Rating: 4 out of 5 stars4/5Learning Python Application Development Rating: 0 out of 5 stars0 ratingsPython Programming: Your Step By Step Guide To Easily Learn Python in 7 Days Rating: 3 out of 5 stars3/5Analysis and Design of Algorithms: A Beginner’s Hope Rating: 0 out of 5 stars0 ratingsPyqt6 101: A Beginner’s Guide to PyQt6 Rating: 0 out of 5 stars0 ratingsComputer Programming In C Language Rating: 4 out of 5 stars4/5Computer Programming Using C Rating: 0 out of 5 stars0 ratingsC Programs To Become Expert In Programming Rating: 0 out of 5 stars0 ratingsBasics of Python Programming: Embrace the Future of Python Rating: 0 out of 5 stars0 ratingsPython for Beginners: A Crash Course to Learn Python Programming in 1 Week Rating: 0 out of 5 stars0 ratingsPython Handbook For Beginners. A Hands-On Crash Course For Kids, Newbies and Everybody Else Rating: 0 out of 5 stars0 ratingsTest-Driven Python Development Rating: 5 out of 5 stars5/5Learning NumPy Array Rating: 0 out of 5 stars0 ratings
Programming For You
SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Microsoft Azure For Dummies Rating: 0 out of 5 stars0 ratingsJavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsBeginning Programming with C++ For Dummies Rating: 4 out of 5 stars4/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5HTML in 30 Pages Rating: 5 out of 5 stars5/5Beginning Programming with Python For Dummies Rating: 3 out of 5 stars3/5PYTHON PROGRAMMING Rating: 4 out of 5 stars4/5Learning Android Forensics Rating: 4 out of 5 stars4/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Python for Data Science For Dummies Rating: 0 out of 5 stars0 ratings
Reviews for Basic Exercises for Competitive Programming
0 ratings0 reviews
Book preview
Basic Exercises for Competitive Programming - Jan Pol
The following book shows a compilation of more than 20 basic exercises for competitive programming, all of them are written in Python. In addition, desktop tests are added to observe the operation of each algorithm.
Hoping you can take knowledge of the pages of this book, my best wishes.
Jan Pol
Exercise 1
Write a program that reads a string S, and prints that line on the standard output in reverse, that is, flipped right-to-left.
Input
The only input has a string S.
Output
Print the string in reverse
Example
Input
1 2 3 hello
Output
olleh 3 2 1
Solution
One way to easily solve this task is to use a loop to print the characters from the last position to the first. This avoids the need to save the reverse list, just print each character.
The code for the solution written in Python is shown below.
1 l = input()
2 i = len(l)
3 while i > 0:
4 i = i - 1
5 print(l[i], end='')
6 print()
Desktop Testing
Doing a desktop testing, it is observed how in each iteration each character is added inversely.
Exercise 2
Given of input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. For example, the sequence for n=5 is as follows:
5→16→8→4→21
Your task is to simulate the execution of the algorithm for a given value of n.
Input
The only input line contains an positive integer n.
Output
Print a line that contains all values of n separated with spaces.
Example
Input
5
Output
5 16 8 4 21
Solution
To solve this task, a cycle is used to verify that the number is not yet 1. Within the cycle it is checked if the